## 46976Re: [libertybasic] help regarding old basic command

Expand Messages
• Sep 2, 2013
Of course!
It's worth anyone who has not realised this to try the following code
which shows the gain.
However, pedagogically ( ie wearing my ex-schoolmaster hat) I've never
met anyone who quotes Pythagoras starting 'The hypotenuse multiplied by
itself is equal to ...', or says 'the power dissipated in a resistor R
carrying I amps is I I R'.
And as always, if speed is important why use a function anyway?

'CODE __________________________________________________
print "Using exponentiation /power function it took ";
now =time\$( "milliseconds")

for i =1 to 100000
result =VS( 2 *i, 3 *i, 4 *i)
next i

print time\$( "milliseconds") -now, " milliseconds"

print "Using multiplication /product function it took ";
now =time\$( "milliseconds")

for i =1 to 100000
result =VS2( 2 *i, 3 *i, 4 *i)
next i

print time\$( "milliseconds") -now, " milliseconds"

print "Using in-line calculation, no function, product rather than
exponentiation, ";
now =time\$( "milliseconds")

for i =1 to 100000
result =2 *i *2 *i+3 *i *3 *i +4 *i *4 *i
next i

print time\$( "milliseconds") -now, " milliseconds"

end
' _____________________________________________________

function VS( x, y, z) ' here we define the function
VS =x^2 +y^2 +z^2
end function

function VS2( x, y, z) ' here we define the function
VS =x*x +y*y +z*z
end function
• Show all 8 messages in this topic