lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Javier Guerra wrote:
> time luajit -e '...'

Please use: luajit -O -e '...'

> [...] t=((a+2^52)-2^52==a)

This is not representative because conditionals are turned into
booleans using a two-way branch. You really want to test something

  if (a+2^52)-2^52 == a then break end

> - both a%1==0 and Mike's hack are much faster than math.floor()

Note that a%1 is internally expanded to a-floor(a/1)*1. The
difference is in the overhead for calling a C closure in the Lua
interpreter. LuaJIT 1.x inlines both (with -O).

Oh, and I wouldn't call the +-2^52 trick a hack. In fact all
modern C compilers use a variation of it to implement floor(),
ceil(), trunc() and round() if the FP is done in hardware, but
doesn't have a special instruction for rounding (e.g. x87 does,
SSE2 and most other FPUs don't).

BTW: All loops are the same speed in LuaJIT 2.x. The condition is
loop-invariant and hoisted, so you end up with an empty loop.
You'll need to get a bit more clever with those microbenchmarks ...