home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!sun1.ruf.uni-freiburg.de!News.BelWue.DE!news.uni-stuttgart.de!cvt11!grether
- From: grether@cvt11.verfahrenstechnik.uni-stuttgart.de (Grether Bernd (sorescu))
- Newsgroups: comp.lang.c
- Subject: Re: C vs. FORTRAN
- Message-ID: <1992Sep4.084823.3406@news.uni-stuttgart.de>
- Date: 4 Sep 92 08:48:23 GMT
- References: <DWISEMAN.92Sep3164036@spsd630a.erim.org>
- Sender: news@news.uni-stuttgart.de (USENET News System)
- Reply-To: grether@cvt11.verfahrenstechnik.uni-stuttgart.de (Grether Bernd (sorescu))
- Organization: Dep.Chem.Eng.(ICVT), Uni Stuttgart, FRG
- Lines: 46
-
- In article <DWISEMAN.92Sep3164036@spsd630a.erim.org>, dwiseman@spsd630a.erim.org (Dave Wiseman) writes:
- |>
- |> 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
-
- [
- code deleted:
-
- loop 1000000 times
- the_sin = sin(...)
- the_cos = cos(...)
- ]
-
- It looks like the Fortran compiler does a better optimization and computes
- the_sin and the_cos only once (the first 999999 results are not used
- in the program).
- These are the times I get on a SPARC2:
-
- Without optimization: C: 12.9s / Fortran: 13.5s
- With optimization: C: 12.4s / Fortran: 0.1s
-
-
- If I declare the_sin and the_cos as arrays (the_sin[i] = sin(...))
- the times are:
-
- Without optimization: C: 14.2s / Fortran: 14.5s
- With optimization: C: 13.2s / Fortran: 14.0s
-
- Now the compiler is forced to compute sin() and cos() a million times.
- Conclusion: your example is too simple. In a non-trivial program you
- wouldn't do a million useless computations (:-)).
-
- --
- Bernd "booster bendi" Grether | Ain't singing for Pepsi
- | ain't singing for Coke
- *** bi uns cha me au | I don't sing for nobody
- alemannisch schwaetze *** | makes me look like a joke (Neil Young)
-