lex pops
2014-08-22 20:37:58 UTC
Hello,
Why does the luajit 'interpreter' run slower than the python
interpreter in this example?
==== sum.lua ====
local ffi = require('ffi')
local function sum_int()
local sum = 0LL
for i=1,10000000 do
sum = sum + i
end
return sum
end
print(sum_int())
==== sum.py ====
def f():
sum = 0
for x in xrange(10000001):
sum += x
return sum
print(f())
====
$ time ./luajit -joff /tmp/sum.lua
50000005000000LL
real 0m0.923s
user 0m0.920s
$ time python /tmp/sum.py
50000005000000
real 0m0.354s
user 0m0.350s
====
Since python uses boxed integers, I expected luajit to meet or beat
python's time. Turning on the jit or using numbers instead of int64s
makes luajit faster by a wide margin.
lex
Why does the luajit 'interpreter' run slower than the python
interpreter in this example?
==== sum.lua ====
local ffi = require('ffi')
local function sum_int()
local sum = 0LL
for i=1,10000000 do
sum = sum + i
end
return sum
end
print(sum_int())
==== sum.py ====
def f():
sum = 0
for x in xrange(10000001):
sum += x
return sum
print(f())
====
$ time ./luajit -joff /tmp/sum.lua
50000005000000LL
real 0m0.923s
user 0m0.920s
$ time python /tmp/sum.py
50000005000000
real 0m0.354s
user 0m0.350s
====
Since python uses boxed integers, I expected luajit to meet or beat
python's time. Turning on the jit or using numbers instead of int64s
makes luajit faster by a wide margin.
lex