home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18855 < prev    next >
Encoding:
Text File  |  1992-12-24  |  1.5 KB  |  41 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!paladin.american.edu!gatech!udel!princeton!jonlab!jon
  3. From: jon@jonlab.UUCP (Jon LaBadie)
  4. Subject: Re: a question about if and case
  5. Message-ID: <1992Dec24.092119.21197@jonlab.UUCP>
  6. Date: Thu, 24 Dec 1992 09:21:19 GMT
  7. References: <1gi6poINN3lv@nz12.rz.uni-karlsruhe.de>
  8. Organization: JG Computing
  9. Lines: 30
  10.  
  11. In article <1gi6poINN3lv@nz12.rz.uni-karlsruhe.de> "hans friedrich steffani" <GM08@DKAUNI2.BITNET> writes:
  12. >
  13. >i have something like
  14. >
  15. Query about efficient "if-elseif-" vs switch code is --- Deleted
  16.  
  17. I recall an article in UNIX World or UNIX Review in about their third
  18. year (circa 1986) that addressed this question for then current compilers.
  19.  
  20. The conclusions (as I remember them) were that there was a cross-over
  21. point at about 3 to 6 "cases".  Fewer than 4, if-else-if was more
  22. efficient.  More than 5, switch/case was more efficient.  This cross
  23. over point was influenced by the nature of the "cases".  A group of
  24. sequential cases favored the switch solution.  Other considerations
  25. were also noted.
  26.  
  27. Based on that article, I would say branch statements with a large
  28. number of destinations should use a switch/case construct, those
  29. with a few destinations should use an if/else-if construct.
  30.  
  31. The above comment is based on an efficiency viewpoint.  Should you
  32. feel one construct is more readable than the other, certainly go
  33. for your preference.
  34.  
  35. Change only when performance has become an issue and you note,
  36. through profiling, that the multi-way branch is a problem.
  37.  
  38. -- 
  39. Jon LaBadie
  40. princeton!jonlab!jon
  41.