A small Lua benchmark including table creation and usage, arithmetics, function calls and upvalues
This file contains 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
| print ("Starting Lua ramp bench") | |
| local startTime = os.clock() | |
| do | |
| local floor = math.floor | |
| local function image_ramp_green(n) | |
| local img = {} | |
| local f = 255/(n-1) | |
| for i=1,n do | |
| img[i] = { red = 0, green = floor((i-1)*f), blue = 0, alpha = 255 } | |
| end | |
| return img | |
| end | |
| local function image_to_grey(img, n) | |
| for i=1,n do | |
| local pixel = img[i] | |
| local y = floor(0.3*pixel.red + 0.59*pixel.green + 0.11*pixel.blue) | |
| local greyPixel = {red = y, green = y, blue = y } | |
| img[i]= greyPixel | |
| end | |
| end | |
| local N = 400*400 | |
| local img = image_ramp_green(N) | |
| for i=1,100 do | |
| image_to_grey(img, N) | |
| end | |
| end | |
| local endtime = os.clock () | |
| print ("Elapsed time: " .. (endtime - startTime)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment