POV-Ray : Newsgroups : povray.general : Making faster #switch statements : Re: Making faster #switch statements Server Time
12 Aug 2024 17:15:24 EDT (-0400)
  Re: Making faster #switch statements  
From: Rudy Velthuis
Date: 5 Mar 1999 17:43:15
Message: <36e05e03.0@news.povray.org>
Ron Parker schrieb in Nachricht <36e03393.0@news.povray.org>...
>>Exactly. IMHO most compilers will do a faster switch() than numerous
>>if-cascades. See also Ron Parker's output of two compilers. They're both
>>faster than a simple cascade of if's would be.
>
>Don't take my stuff as gospel, though.  I reverse-engineer stuff for a
>living, so what you see is from memory, probably not 100% accurate,
>could have even been hand-coded by some masochist, and is almost
>certainly filtered through my "understand-o-meter"


I don't do it for a living, but I've seen enough code (Pascal and C
disassembly) like the samples you showed to believe this is the way most
switch statements (should) work. Even the example Thorsten showed seems to
do this (although it was hard to recognise at a first glance).

>I don't know what about switch in POV would make it slow, other than the
>requirement that it parse even the parts it doesn't use, to find the parts
>it needs.  In this case, an array would be the best bet.  In other cases,
>it's mostly empirical.  The idea should be to minimize the amount of
>text in each case, but that won't always be the best solution either.

I don't know how the parser handles a #switch, but I'd expect it to look for
the end of the #switch block when it encounters #break and to look for the
next #case or #range, when a #case/#range check fails. Don't know how this
could be improved easily.

--
Rudy Velthuis


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.