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