Skip to content

Instantly share code, notes, and snippets.

@pcarrier
Created July 22, 2009 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcarrier/151987 to your computer and use it in GitHub Desktop.
Save pcarrier/151987 to your computer and use it in GitHub Desktop.
guess = function(a,b)
return a==0 and b
or b==0 and a
or a>b and guess(a-b,b)
or guess(a,b-a)
end
function guess2(a,b)
if (a==0) then
return b
elseif (b==0) then
return a
elseif (a>b) then
return guess2(a-b,b)
else
return guess2(a,b-a)
end
end
function timed(fn)
local starttime = os.clock()
fn()
local endtime = os.clock()
print("It took " .. (endtime-starttime) .. "s!")
end
function repeated(fn, m, n)
return
function()
for i = 1, m do
for j = 1, n do
fn(i, j)
end
end
end
end
timed(repeated(guess,1000,1000))
timed(repeated(guess2,1000,1000))
It took 3.593s!
It took 3.407s!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment