home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 13215 < prev    next >
Encoding:
Internet Message Format  |  1992-09-04  |  2.2 KB

  1. 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
  2. From: grether@cvt11.verfahrenstechnik.uni-stuttgart.de (Grether Bernd (sorescu))
  3. Newsgroups: comp.lang.c
  4. Subject: Re: C vs. FORTRAN
  5. Message-ID: <1992Sep4.084823.3406@news.uni-stuttgart.de>
  6. Date: 4 Sep 92 08:48:23 GMT
  7. References: <DWISEMAN.92Sep3164036@spsd630a.erim.org>
  8. Sender: news@news.uni-stuttgart.de (USENET News System)
  9. Reply-To: grether@cvt11.verfahrenstechnik.uni-stuttgart.de (Grether Bernd (sorescu))
  10. Organization: Dep.Chem.Eng.(ICVT), Uni Stuttgart, FRG
  11. Lines: 46
  12.  
  13. In article <DWISEMAN.92Sep3164036@spsd630a.erim.org>, dwiseman@spsd630a.erim.org (Dave Wiseman) writes:
  14. |> 
  15. |> Help!
  16. |> 
  17. |> I have a (two) simple programs, one in fortran, and one in C.  I have compiled
  18. |> them both optimized, and timed the results.  The fortran version takes .1 s
  19. |> to run, and the C version takes 12.5s to run.  I know (hope) that there is a
  20. |> simple remedy for this.  The project that I am working on has to do many 
  21. |> sines and cosines, and I'd prefer to keep the entire program in C, and not
  22. |> mix the languages.  What can I do to improve the speed of the C version?
  23. |> 
  24. |>     Dave Wiseman
  25. |>     dwiseman@erim.org
  26.  
  27. [
  28. code deleted:
  29.  
  30. loop 1000000 times
  31.   the_sin = sin(...)
  32.   the_cos = cos(...)
  33. ]
  34.  
  35. It looks like the Fortran compiler does a better optimization and computes
  36. the_sin and the_cos only once (the first 999999 results are not used
  37. in the program).
  38. These are the times I get on a SPARC2:
  39.  
  40. Without optimization: C: 12.9s / Fortran: 13.5s
  41. With optimization:    C: 12.4s / Fortran:  0.1s
  42.  
  43.  
  44. If I declare the_sin and the_cos as arrays (the_sin[i] = sin(...))
  45. the times are:
  46.  
  47. Without optimization: C: 14.2s / Fortran: 14.5s
  48. With optimization:    C: 13.2s / Fortran: 14.0s
  49.  
  50. Now the compiler is forced to compute sin() and cos() a million times.
  51. Conclusion: your example is too simple. In a non-trivial program you
  52. wouldn't do a million useless computations (:-)).
  53.  
  54. -- 
  55. Bernd "booster bendi" Grether | Ain't singing for Pepsi
  56.                               | ain't singing for Coke
  57. *** bi uns cha me au          | I don't sing for nobody
  58.     alemannisch schwaetze *** | makes me look like a joke (Neil Young)
  59.