home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!sun-barr!ames!haven.umd.edu!darwin.sura.net!jvnc.net!yale.edu!yale!gumby!destroyer!csd475b!newsserv!dwiseman
- From: dwiseman@spsd630a.erim.org (Dave Wiseman)
- Subject: C vs. FORTRAN
- Message-ID: <DWISEMAN.92Sep3164036@spsd630a.erim.org>
- Sender: news@newsspool.erim.org
- Organization: Environmental Research Institute of Michigan, Ann Arbor, Michigan
- Date: 3 Sep 92 16:40:36
- Lines: 55
-
-
- Help!
-
- I have a (two) simple programs, one in fortran, and one in C. I have compiled
- them both optimized, and timed the results. The fortran version takes .1 s
- to run, and the C version takes 12.5s to run. I know (hope) that there is a
- simple remedy for this. The project that I am working on has to do many
- sines and cosines, and I'd prefer to keep the entire program in C, and not
- mix the languages. What can I do to improve the speed of the C version?
-
- Dave Wiseman
- dwiseman@erim.org
-
- -------------------------------------------------------------------------------
- #include <stdio.h>
- #include <math.h>
-
- main (argc,argv)
- int argc;
- char **argv;
- {
- double angle,delta,the_sin,the_cos;
- int i;
-
- angle = 0.0;
- delta = 0.01;
-
- for (i=0; i<1000000; i++)
- {
- the_sin = sin(angle);
- the_cos = cos(angle);
- angle += delta;
- }
- }
- -------------------------------------------------------------------------------
- program test
-
- real*8 angle,delta,the_sin,the_cos
- integer*4 i
-
- angle = 0.0
- delta = 0.01
-
- do I=1,1000000
- the_sin = dsin(angle)
- the_cos = dcos(angle)
- angle = angle + delta
- enddo
-
- end
- -------------------------------------------------------------------------------
- --
- David Wiseman dwiseman@erim.org
- Environmental Research Institute of Michigan
-
-