lua-users home
lua-l archive

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


Hi,

Tom Spilman wrote:
>  The Great Computer Language Shootout has a new maintainer and it's been
> updated to include Lua 5.0.2.
> 
>   http://shootout.alioth.debian.org/

Well ... Lua has some trouble there, because:

- I guess they compiled Lua with the default settings, i.e. "-O" if we are
  lucky. All other languages have some kind of configure script that sets
  various compiler options to tune them to the max. Someone needs to contact
  the maintainer of the Lua Debian package. Since their policies on compiler
  flags are somewhat debatable, you may have a hard time.

- Some of the Lua scripts there are not optimal (no locals, no use
  of Lua specific tricks, braces preventing the use of tail calls ...).
  Compared to the tricks used for other languages the Lua scripts are tame.
  The Ackermann test seems to fail. Some tests are missing.

- Seems they accept now the use of external C libraries like NumPy to tune
  some of the tests (e.g. matrix multiplication). This certainly moves the
  scope of the shootout from 'language' to 'language + toolset'.

- I cannot access some areas of the website (e.g. the tarball download)
  because some of the links and/or some of the PHP scripts are faulty.
  This is not to criticize their efforts, but I'm simply lacking some
  information required to see whether Lua is treated fairly.

I've attached some tests that were easy to tune:

ackermann    +7%  (and avoiding a stack overflow)
fibo         +8%
hash2        +5%
random      +19%
strcat      +55%

[The timing comparisons were done with a fully optimized Lua-5.1-work2,
 but should apply to Lua-5.0.2, too.
 BTW: The getnum patch I sent in the other day, improves the speed of hash2
 by another 4-5%.
]

There is more to tune. If someone has the time, please collect the revised
scripts and submit them to the maintainer.

Bye,
     Mike
local function Ack(m, n)
  if m == 0 then return n+1 end
  if n == 0 then return Ack(m-1, 1) end
  return Ack(m-1, Ack(m, n-1))
end

N = tonumber((arg and arg[1]) or 1)
io.write("Ack(3,", N ,"): ", Ack(3,N), "\n")
local function fib(n)
  if (n < 2) then return 1 end
  return fib(n-2) + fib(n-1)
end

N = tonumber((arg and arg[1]) or 1)
io.write(fib(N), "\n")
local n = tonumber((arg and arg[1]) or 1)

local hash1 = {}
for i=0,10000 do
  hash1["foo_"..i] = i
end

local hash2 = setmetatable({}, {__index=function() return 0 end})
for i=1,n do
  for k,v in hash1 do
    hash2[k] = v + hash2[k]
  end
end

io.write(string.format("%d %d %d %d\n", hash1["foo_1"], hash1["foo_9999"],
  hash2["foo_1"], hash2["foo_9999"]))
local IM = 139968
local IA = 3877
local IC = 29573

local mod = math.mod
local LAST = 42
local function gen_random(max)
    LAST = mod(LAST * IA + IC, IM)
    return (max * LAST) / IM
end

local N = tonumber((arg and arg[1]) or 1)
local result = 0
for i=1, N do
    result = gen_random(100)
end
io.write(string.format("%.9f\n", result))
local n = tonumber((arg and arg[1]) or 1)
local buff = {}
for i=1,n do
  buff[i] = "hello\n"
end
local s = table.concat(buff, "", 1, n)
print(string.len(s))