-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How does Moses compare to Lua Fun? #70
Comments
This project is alive and Luafun is dead, but Moses does not do things in lazy way. Performance difference is huge, so I continue to use Luafun that works great. But I wish that code could be borrowed from Luafun. Some performance tests here: #58 |
Lua Fun was specifically designed to take advantage of the JIT in LuaJIT. I am not able to take advantage of the LuaJIT in my project as I am using the golang fork of Lua runtime. That means Lua Fun does not make sense for me. |
Lazy evaluation has nothing to do with Luajit. Lazy libraries just do much less iterations than non-lazy versions and that's the reason why they are so much faster. In my quick test luafun is 6667 times faster than moses using PUC Lua. -- fn-test.lua
local _ = require "moses" -- https://github.com/Yonaba/Moses/blob/master/doc/tutorial.md
local fn = require "fun" -- https://github.com/rtsisyk/luafun
local arr = {}
math.randomseed(os.time())
for i = 1, 10^6 do
local rand = math.random(1, 100)
arr[i] = {rand = rand, str = string.rep("x", rand)}
end
local function filterFn(rec)
return rec.rand % 2 == 0
end
local function mapFn(rec)
return rec.rand + 0.1
end
local time1 = os.clock()
local gen1 = fn.iter(arr):filter(filterFn):map(mapFn):take(3):totable()
time1 = os.clock() - time1
print(string.format('%.6f seconds: %s', time1, table.concat(gen1, ', ')))
local time2 = os.clock()
local gen2 = _(arr):filter(filterFn):map(mapFn):take(3):value()
time2 = os.clock() - time2
print(string.format('%.6f seconds: %s', time2, table.concat(gen2, ', ')))
print(string.format("time1: %.6f / time2: %.6f, luafun is %.0f times faster than moses", time1, time2, time2/time1)) Luajit 2.1: PUC Lua 5.1: |
wrong way bench. it dont make sense. |
@denisdemaisbr Hi, can you explain why bench is wrong? Or can you give better bench? Thanks. |
afaict I think the main difference is that moses always creates intermediate tables, but luafun mainly works with iterators themselves? |
Apart from being more active, how does Moses compare to Lua Fun?
The text was updated successfully, but these errors were encountered: