GLBasic forum

Codesnippets => Code Snippets => Topic started by: Qedo on 2011-Sep-17

Title: POW speed
Post by: Qedo on 2011-Sep-17
Don't use POW function  for value of power less or ugual to 40. It is very slow
Try this code
Ciao


[attachment deleted by admin]
Title: Re: POW speed
Post by: MrTAToad on 2011-Sep-17
My timings (on the PC) are including.  Wonder why its 10 times slower ? :blink:

[attachment deleted by admin]
Title: Re: POW speed
Post by: Moebius on 2011-Sep-18
POW allows exponents that aren't positive integers, hence requiring more complicated code than multiplying the base out a few times :P
Title: Re: POW speed
Post by: Qedo on 2011-Sep-18
Right
Try this for negative elevations (not too complicated) :).   Is always faster
Obviously this program does not work for elevations greater than 0 and less than 1
Ciao

[attachment deleted by admin]
Title: Re: POW speed
Post by: Qedo on 2011-Sep-18
I forgot to add that the elevations should not be decimal.
3, 5, 6, -4, -6 yes
-3,5, 5.67   no
Ciao
Title: Re: POW speed
Post by: Moebius on 2011-Sep-18
Which is exactly where POW differs from this integer exponent functions  :good:
Title: Re: POW speed
Post by: Qedo on 2011-Sep-18
But where it is very useful in calculations of the type Bezier algorithm:
B(t)=(1-t)5P1 + 5t(1-t)4P2 + 10t2(1-t)3P3 + 10t3(1-t)2P4 + 5t4(1-t)P5+ t5P6
Ciao
Title: Re: POW speed
Post by: Kitty Hello on 2011-Sep-19
it'S 10x slower, because it's a very quick function, that calls the native "pow", which is also very quick. I think the delay comes from the calling overhead.