Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.