Author Topic: POW speed  (Read 2423 times)

Offline Qedo

  • Mr. Polyvector
  • ***
  • Posts: 164
  • UNUS SED LEO
    • View Profile
POW speed
« 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]

MrTAToad

  • Guest
Re: POW speed
« Reply #1 on: 2011-Sep-17 »
My timings (on the PC) are including.  Wonder why its 10 times slower ? :blink:

[attachment deleted by admin]
« Last Edit: 2011-Sep-17 by MrTAToad »

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: POW speed
« Reply #2 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
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Offline Qedo

  • Mr. Polyvector
  • ***
  • Posts: 164
  • UNUS SED LEO
    • View Profile
Re: POW speed
« Reply #3 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]

Offline Qedo

  • Mr. Polyvector
  • ***
  • Posts: 164
  • UNUS SED LEO
    • View Profile
Re: POW speed
« Reply #4 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

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: POW speed
« Reply #5 on: 2011-Sep-18 »
Which is exactly where POW differs from this integer exponent functions  :good:
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Offline Qedo

  • Mr. Polyvector
  • ***
  • Posts: 164
  • UNUS SED LEO
    • View Profile
Re: POW speed
« Reply #6 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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: POW speed
« Reply #7 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.