POV-Ray : Newsgroups : povray.text.tutorials : Tips & tricks: How speed-up calculations in loops - part II : Tips & tricks: How speed-up calculations in loops - part II Server Time: 24 Apr 2014 13:11:35 GMT
  Tips & tricks: How speed-up calculations in loops - part II  
From: W³odzimierz ABX Skiba
Date: 11 Feb 2002 11:39:01
Inspired by the result of previous test I've made another benchmark:
How functions speed-up simplest expressions - in this case I wondered what
about loop indexing.

I compared speed of two scripts:

//SCRIPT 1
#local dec=function(N){N-1};
#local C=1000000;
#while(C)
#local C=dec(C);
#end

and

//SCRIPT 2
#local C=1000000;
#while(C)
#local C=C-1;
#end

Note difference: first script use function to decrease value of parameter.
Both scripts were started three times on PII 233 with 128 MB (3.5 b 11).
Result: measuring CPU time first script was little faster then second about:
- kernel time: 5,64%
- user time: 11,00%
- total time: 9,38%

Then I compared the same replacement for increased index of loop.

//SCRIPT 3
#local inc=function(N){N+1};
#local C=0;
#while(C<1000000)
#local C=inc(C);
#end

and

//SCRIPT 4
#local C=0;
#while(C<1000000)
#local C=C+1;
#end

In this case there is no difference in speed. It changed from test to test. It
was around +/- 2%. Not big deal in this case.

Additional note: there was the same number of interations but version with
decreasing was faster (20-30%) than version with increasing (probably becouse
of no additional tokens in loop condition).

Any comments ?

ABX


Post a reply to this message

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