lua-users home
lua-l archive

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

For a benchmark, "Leo Razoumov" <> writes:

> local sum=0
> for x=1,10000000 do
>     sum= sum+ 100/50
> end


I decided on a different performance test, one that repeatedly
computes a remainder.  On an IBM IntelliStation M Pro, which uses a
32-bit i386, I compiled a patched and an unpatched version of Lua
5.1.3 with "make ansi".  I then ran the following benchmark.

$ cat mod.lua
local sum = 0
for i = 1,100000000 do
   sum = sum + i % 5
print (sum)
$ : Unpatched lua 
$ time lua-5.1.3/src/lua mod.lua 

real    0m8.321s
user    0m8.286s
sys     0m0.003s
$ : Lua patched with "Go Long Lua!"
$ time plua-5.1.3/src/lua mod.lua 

real    0m6.196s
user    0m6.170s
sys     0m0.002s

So there really is a performance difference between longs and doubles,
even on machines with FPUs.  Note that remainder is an important
component in some cryptography algorithms.

Since it's a 32-bit machine, I'm curious to know if ints are faster
than longs, however, that requires modifying my patch.  Maybe I'll try
that experiment when I have some free time.  

I bet longs are even faster on a 64-bit machine, a Core 2 Duo or one
of AMD's processors.  I'll see if I can find a machine that allows
that hypothesis to be tested too.