[Box Backup-dev] [PATCH] Win32 merge [05] bbackupd
Martin Ebourne
boxbackup-dev@fluffy.co.uk
Wed, 09 Aug 2006 10:57:55 +0100
Chris Wilson <chris@qwirx.com> wrote:
>> For compilers switches are more efficient, if's and elsifs if it is =20
>> the last match then it runs them all, typically a lot of compilers =20
>> compile switch statements into jump tables (AFAIK).
Nick is in general right with that. I'm not sure if any compilers are =20
good enough to optimise an if/else chain into a switch, though I don't =20
see any reason why they shouldn't.
> Premature optimisation is the root of all evil :-)
Yes, true enough.
> I'd favour
> readability over efficiency until we have a measurable efficiency
> problem (not just a few machine cycles of comparing ints).
Definitely. So use switch until if/else is proven to give a =20
significant performance boost. ;-)
One other point I forgot in my last mail: You said that if/else is =20
easier to read because the exact condition is always to hand. Of =20
course, this is completely untrue. In a long if/else chain you have to =20
check every single condition above the one you are looking at to see =20
what the actual condition is.
I shalln't post on this topic again, I promise. :)
Cheers,
Martin.