Lodash fp v4 flow vs Native
Date tested:
10 months ago
User agent:
Mozilla/5.0 (Android 14; Mobile; rv:109.0) Gecko/119.0 Firefox/119.0
Test name
Executions per second
lodash fp
1003309.0 Ops/sec
native
17580630.0 Ops/sec
native with lodash
4565358.0 Ops/sec
native with named funcs
12890920.0 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/g/lodash@4(lodash.min.js+lodash.fp.min.js)'></script>
Script Preparation code:
var fp = _.noConflict(); var context = { eventline: { hello: 'you' }, config: 'sadas', }; var isString = fp.isString; var isArray = fp.isArray; var getDefaultProps = fp.flow( fp.filter( _.overEvery([ isString, function (prop) { return _.hasIn(context, prop); }, ]), ), fp.reduce(function (acc, i) { acc[i] = context[i]; return acc; }, {}), ); var testNative = function(param) { param.filter(myVar => (typeof myVar === 'string' || myVar instanceof String) && context[myVar]).reduce(function (acc, i) { acc[i] = context[i]; return acc; }, {}) } var testNativeDash = function(param) { param.filter(myVar => _.isString(myVar) && _.hasIn(context, myVar)).reduce(function (acc, i) { acc[i] = context[i]; return acc; }, {}) } var isStr = myVar => typeof myVar === 'string' || myVar instanceof String; var isWithinObj = myVar => !!context[myVar]; var reducer = function (acc, i) { acc[i] = context[i]; return acc; } var testNativeWithFunc = function(param) { param.filter(myVar => isStr(myVar) && isWithinObj(myVar)).reduce(reducer, {}) } var test1 = ['eventline']
Tests:
lodash fp
getDefaultProps(test1);
native
testNative(test1)
native with lodash
testNativeDash(test1)
native with named funcs
testNativeWithFunc(test1)
Open this result on MeasureThat.net