Skip to content

Instantly share code, notes, and snippets.

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

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
return os.clock() - now
print("math.fmod: "..fold(function() return math.fmod(255, 8) end, 10000000))
print("%: "..fold(function() return 255 % 8 end, 10000000))
print("&: "..fold(function() return, 7) end, 10000000))

This comment has been minimized.

Copy link
Owner Author

dpino 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.