odd and even numbers

Mark Wieder mwieder at ahsoftware.net
Mon Aug 5 21:05:28 EDT 2013


Alex-

The problem with things like mod and "/" is that they're expensive in
terms of scaling: they're about 3.5 times slower than "last char". If
you're just doing this once, it shouldn't matter much. But if you need
to determine oddness in a loop you want to do as much processing
outside the loop as possible.

Here's the fastest I could come up with...

constant kEven="02468"
put 3.14169 into tValue
-- do this outside the loop
put trunc(tValue) into y
put the milliseconds into x
repeat 10000 times
-- this line is slow
-- put the last char of trunc(y) is in kEven into tIsEven
-- much faster
put the last char of y is in kEven into tIsEven
end repeat
put the milliseconds -x

-- 
-Mark Wieder
 mwieder at ahsoftware.net





More information about the use-livecode mailing list