Skip to content

Instantly share code, notes, and snippets.

@jlj
Created February 5, 2016 13:39
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 jlj/de7d8be6f1160ea2963c to your computer and use it in GitHub Desktop.
Save jlj/de7d8be6f1160ea2963c to your computer and use it in GitHub Desktop.
A small Lua benchmark including table creation and usage, arithmetics, function calls and upvalues
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