home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12223 < prev    next >
Encoding:
Text File  |  1992-08-12  |  1.9 KB  |  51 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!destroyer!ubc-cs!van-bc!tram!jeffrey
  3. From: jeffrey@squid.tram.com (Jeffrey L Bromberger)
  4. Subject: Re: Optimizing code for tests
  5. Organization: Tramway Unix Systems
  6. Date: Wed, 12 Aug 1992 15:31:58 GMT
  7. Message-ID: <1992Aug12.153158.13990@squid.tram.com>
  8. Keywords: CC GCC f77
  9. References: <1992Aug11.162502.8848@squid.tram.com>
  10. Lines: 39
  11.  
  12. In article <1992Aug11.162502.8848@squid.tram.com> I wrote:
  13.  
  14. >with the random number generator; it may be fast, but 50% of my time
  15. >is spent there...
  16.  
  17. So far, all I have gotten in reply is "50%?!?!?"  I have gotten
  18. comments like:
  19.  
  20. Don't use rand()      I already don't
  21. Use *this* one        I've got a nice one, thanks
  22. It should be small    So it is...
  23.  
  24. Maybe I'll have to explain.  The generator is not at fault.  The
  25. problem is that it gets called nearly 2^15 times for each simulated
  26. "event".  Make that now 30,000 events repeated over 30,000 simulated
  27. years (for a small run) and you're talking about (Carl Sagan Mode ON)
  28. Millyuns and Millyuns :-)
  29. of calls to the generator.  Prof tells me it's the fastest of all
  30. routines, clocking in at 0.04msec per run.  It still adds up.
  31.  
  32. One suggestion I'd like to know more about, but have no idea where to
  33. follow it up is "make the generator in-line code".  Any pointers on
  34. this idea?  Does it just involve moving a copy of the generator code
  35. everywhere it's called (as opposed to having it's own function)?
  36.  
  37. >What I am trying to optimize are my comparisons.
  38. >So, is it really worth my while to worry about which path is fastest?
  39.  
  40. Honestly, everyone (except for one passing remark) seems to be
  41. avoiding the question I posed.  Is the compiler really doing anything
  42. different speed-wise if the test passes or fails?  Should I just give
  43. up on this point?  Stick to it just for the sake of coherent style?
  44.  
  45. Thanks!
  46.  
  47. j
  48. -- 
  49. Jeffrey L. Bromberger ------- System Manager ------- Tramway Unix Systems
  50. jeffrey@squid.tram.com      Anywhere!{van-bc,limbic,icus}!tram!jeffrey
  51.