From -4012858817936338799
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,5be30c38f618a07b
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-05-06 07:52:01 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: James Kanze <kanze@alex.gabi-soft.de>
Newsgroups: comp.std.c++
Subject: Re: Why switch w/ only integral types?
Date: Mon,  6 May 2002 14:51:17 GMT
Organization: James Kanze
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <86d6w9a76w.fsf@alex.gabi-soft.de>
References: <6ee7d287.0203202005.63e0b7b3@posting.google.com> <qfpm8.12422$cy2.680922353@newssvr21.news.prodigy.com> <3CCE6310.672E55DF@webmaster.com> <aatv35$dm69h$1@ID-97366.news.dfncis.de>
X-Trace: mail2news.demon.co.uk 1020696682 mail2news:1567 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
X-MIME-Autoconverted: from 8bit to quoted-printable by mailbox2.ucsd.edu id g46ASDF5021935
X-MIME-Autoconverted: from quoted-printable to 8bit by mulga.cs.mu.OZ.AU id UAA23732
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mulga.cs.mu.OZ.AU id AAA10979
Lines: 37
Xref: archiver1.google.com comp.std.c++:11063

"Pavel Kuznetsov" <pavel@despammed.com> writes:

|>  David Schwartz (davids@webmaster.com) wrote:

|>  DS> and on many platforms is actually slower than corresponding
|>  DS> if/else code at low levels of optimization.

|>  At least on one platform code generated from switch/case is a lot
|>  faster than that from if/else if.=20

More generally, I would say that the code generated for switch/case
should never be slower than that for if/else if. Because generating a
series of if/else if is a perfectly legitimate way of implementing
switch/case, and if it is the fastest way, the compiler should choose
it.

In practice, I cannot conceive of an architecture on which switch/case
would not be faster for at least some cases of switches.

|>  And of course speed is not right factor for choosing between
|>  if/else and case. Readability and ease of maintainance is.

Unless, of course, profiling has shown that there is a problem, and
that the problem is due to the implementation of switch.

--=20
James Kanze                                mailto:kanze@gabi-soft.de
Conseils en informatique orient=E9e objet/
                    Beratung in objektorientierter Datenverarbeitung
Ziegelh=FCttenweg 17a, 60598 Frankfurt, Germany Tel. +49(0)179 2607481

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



