POV-Ray : Newsgroups : povray.general : Making faster #switch statements : Re: Making faster #switch statements Server Time
12 Aug 2024 09:17:31 EDT (-0400)
  Re: Making faster #switch statements  
From: Remco de Korte
Date: 4 Mar 1999 22:46:41
Message: <36DF5350.C7DA7158@xs4all.nl>
Assuming you're using 3.01 why not use a (small) array?
That's probably the fastest you can get.

Regards,

Remco

Martin Magnusson wrote:
> 
> I'm working on a method of making cloth, and I posted a version of it in
> .binaries.animations, but now I'm trying to make it faster. I used to have
> this statement
> 
> #declare Unstretched = sqrt(pow(k*Normal_Length,2) +
> pow(l*Normal_Length,2));
> 
> which is evaluated 24*16*16*4 times for each frame. Since Unstretched really
> can have only five values, I thought I should precompute them and use a
> #switch statement to choose, so I changed that line for the following:
> 
> #switch (abs(k) + abs(l))
>   #case (1)  #declare Unstretched = Unstretched1;  #break
>   #case (2)
>     #if ((k=0) | (l=0))
>       #declare Unstretched = Unstretched3;
>     #else
>       #declare Unstretched = Unstretched2;
>     #end
>   #break
>   #case (3)  #declare Unstretched = Unstretched5;  #break
>   #case (4)  #declare Unstretched = Unstretched4;  #break
> #end
> 
> but it seems like that *increased* the parse time by about 50%. I thought
> that just picking a precomputed value would be faster than calculating
> Pythagoras' theorem. Did I do something wrong, or is #switch really that
> slow?
> 
> --
> Martin Magnusson
> e-mail: Mar### [at] studentuuse
> www-site: http://www.geocities.com/SoHo/9946/


Post a reply to this message

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