[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Fastest way to determine number is integer in plain Lua**
**From**: "Javier Guerra" <javier@...>
**Date**: Fri, 7 Nov 2008 11:12:49 -0500

testing...
plain Lua:
time lua -e 'local a=1.5;local f=math.floor;for i=1,1e8 do local
t=(f(a)==a) end'
real 0m16.597s
user 0m16.161s
sys 0m0.008s
time lua -e 'local a=1.5;for i=1,1e8 do local t=(a%1==0) end'
real 0m10.110s
user 0m9.853s
sys 0m0.008s
time lua -e 'local a=1.5;for i=1,1e8 do local t=((a+2^52)-2^52==a) end'
real 0m9.944s
user 0m9.641s
sys 0m0.016s
LuaJIT 1.1.4
time luajit -e 'local a=1.5;local f=math.floor;for i=1,1e8 do local
t=(f(a)==a) end'
real 0m8.000s
user 0m7.680s
sys 0m0.000s
time luajit -e 'local a=1.5;for i=1,1e8 do local t=(a%1==0) end'
real 0m1.133s
user 0m1.116s
sys 0m0.008s
time luajit -e 'local a=1.5;for i=1,1e8 do local t=((a+2^52)-2^52==a) end'
real 0m1.874s
user 0m1.824s
sys 0m0.004s
conclusions:
- both a%1==0 and Mike's hack are much faster than math.floor()
- there's very little difference between them, Mike's is 3% faster
- math.floor() doesn't get much benefit from LuaJIT
- a%1==0 is the most improved by LuaJIT, (8.8 times!) becomes 40%
faster than Mike's hack
i'd use a%1==0, since it's the most readable
--
Javier