Created
July 22, 2009 12:32
-
-
Save pcarrier/151987 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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