lua-users home
lua-l archive

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


Work 6 performs *much* worse than work 5 (and 5.0.2 even!) on the test script below (About 70% (!) slower for sumi and about 30% for sumr.) What's going on?


local function sumi(n, r)
  while r > 0 do
    n = n + r
    r = r - 1
  end
  return n
end

local function sumr(n, r)
  if r > 0 then
    return sumr(n + r, r - 1)
  end
  return n
end

local now = os.clock()
for i = 1, 1000 do sumi(0, 10000) end
now = os.clock() - now

print(string.format("iterative version took %.3f seconds", now))

now = os.clock()
for i = 1, 1000 do sumr(0, 10000) end
now = os.clock() - now

print(string.format("recursive version took %.3f seconds", now))


--
Wim