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