Comments (6)
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:
0.000028 seconds: 48.1, 72.1, 52.1
0.104055 seconds: 48.1, 72.1, 52.1
time1: 0.000028 / time2: 0.104055, luafun is 3716 times faster than moses
PUC Lua 5.1:
0.000058 seconds: 90.1, 38.1, 78.1
0.386687 seconds: 90.1, 38.1, 78.1
time1: 0.000058 / time2: 0.386687, luafun is 6667 times faster than moses
from moses.
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
from moses.
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.
from moses.
wrong way bench. it dont make sense.
from moses.
wrong way bench. it dont make sense.
@denisdemaisbr Hi, can you explain why bench is wrong? Or can you give better bench? Thanks.
from moses.
afaict I think the main difference is that moses always creates intermediate tables, but luafun mainly works with iterators themselves?
from moses.
Related Issues (20)
- range(1,1) returns empty array HOT 4
- sortBy API doc claims it sorts in-place, but it does not HOT 1
- Feature request: findWhere(t, f) HOT 1
- Feature request: unzip HOT 4
- Feature request: unpack() HOT 2
- sample() fails when array contains middleclass classes HOT 7
- Many functions not chainable because of f(i,k) 1st arg HOT 4
- Use of underscore ("_") and "M" from Lua Style Guide
- Bug in Intersect, Questions about Difference and Union HOT 1
- Syntax and performance questions? HOT 6
- Links in documentation not working correctly
- M.compose() HOT 6
- uid() alias refers to non-existent uniqueid() HOT 1
- 2.x is compatible with 1.x ? HOT 1
- powerset does not generate a power set HOT 1
- Don't treat io or os modules as mandatory (redis compatibility) HOT 4
- Feature request: mapi() HOT 2
- Interview With Moses Author?
- Please make moses available for 5.4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moses.