Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Lodash reduce filter vs Native reduce filter vs Lodash filter vs Native filter
compare filter methods on arrays that both modify objects and remove items from the array.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:125.0) Gecko/20100101 Firefox/125.0
Browser:
Firefox 125
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Reduce filter
57870372.0 Ops/sec
Lodash reduce filter
39526032.0 Ops/sec
Native filter
51568620.0 Ops/sec
Lodash filter
39434636.0 Ops/sec
Reduce modify
46049584.0 Ops/sec
Map modify
49063268.0 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var testCopy = null; var testArray = [{ id: 1, description: 'Random description.', testDate: new Date(), testBoolean: true, testObject: { testString: 'test string', testNumber: 12345 }, testArray: [{ myName: 'test name', myNumber: 123245 }] },{ id: 2, description: 'Random description.', testNumber: 123456789, testBoolean: true, testObject: { testString: 'test string', testNumber: 12345 }, testArray: [{ myName: 'test name', myNumber: 123245 }] }];
Tests:
Reduce filter
testCopy = testArray.reduce((accumulator, currentValue) => { if(currentValue.id != 2) { currentValue.description = 'test'; accumulator.push(currentValue); return accumulator; } return accumulator; },[])
Lodash reduce filter
testCopy = _.reduce(testArray,(accumulator, currentValue) => { if(currentValue.id != 2) { currentValue.description = 'test'; accumulator.push(currentValue); return accumulator; } return accumulator; },[]);
Native filter
testCopy = testArray.filter(o => { if(o.id != 2) { o.description = 'test'; return o; } });
Lodash filter
testCopy = _.filter(testArray, function(o) { if(o.id != 2) { o.description = 'test'; return o; } });
Reduce modify
testCopy = testArray.reduce((accumulator, currentValue) => { if(currentValue.id == 2) { currentValue.description = 'test'; accumulator.push(currentValue); return accumulator; } return accumulator; },[])
Map modify
testCopy = testArray.map((item)=>{ if(item.id == 2){ item.description = 'test'; } return item; });