home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18475 < prev    next >
Encoding:
Text File  |  1992-12-16  |  1.3 KB  |  32 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: SWITCH Statement Question
  5. Message-ID: <1992Dec16.170819.25568@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Dec15.122456.1776@hellgate.utah.edu>
  8. Distribution: usa
  9. Date: Wed, 16 Dec 1992 17:08:19 GMT
  10. Lines: 20
  11.  
  12. u-mwong%peruvian.cs.utah.edu@cs.utah.edu (Michael Wong) writes:
  13.  
  14. >   Will using a SWITCH statement run faster if it had few CASE statements and 
  15. >IF statements were used to aid in the processing than using a SWITCH 
  16. >statement that had a very long list of CASE statements.
  17.  
  18. It depends entirely on the compiler.  Some compilers will generate nearly
  19. identical code for both methods.  Some will generate "better" code for
  20. one than for the other.  "Better" might mean "smaller" or "faster" or both.
  21.  
  22. Invariable rule:  Write straightforward code that is easy to read,
  23. understand, and modify.  This will be easier to get working, and will
  24. be easier to see as being correct.  If you find BY MEASUREMENT that a
  25. code fragment is the bottleneck which is slowing your program, look for
  26. ways to make it faster.  Keep around the original code, since source
  27. code that gives better results with one compiler/machine combination may
  28. give worse results with a different combination.
  29. -- 
  30.  
  31. Steve Clamage, TauMetric Corp, steve@taumet.com
  32.