Skip to content

Instantly share code, notes, and snippets.

@dpino dpino/modulo.lua
Created Jan 4, 2019

Embed
What would you like to do?
Microbenchmark for LuaJIT's modulo operations
local C = ffi.C
function fold(fn, times)
local now = os.clock()
for i=1,times do
fn()
end
return os.clock() - now
end
print("math.fmod: "..fold(function() return math.fmod(255, 8) end, 10000000))
print("%: "..fold(function() return 255 % 8 end, 10000000))
print("&: "..fold(function() return bit.band(255, 7) end, 10000000))
@dpino

This comment has been minimized.

Copy link
Owner Author

commented Jan 4, 2019

Example of execution:

$ luajit modulo.lua
math.fmod: 0.243867
%: 0.003274
&: 0.003262

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.