Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
merge object by key from array with lodash
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Array.prototype.reduce()
1190398.5 Ops/sec
_.reduce()
1075433.4 Ops/sec
_.reduce() with _.get()
512104.6 Ops/sec
_.keyBy()
1224186.9 Ops/sec
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.5/lodash.min.js"></script>
Script Preparation code:
var key = 'key'; var object = { 'a': { 'key': 'a', 'foo': 123123, 'bar': 123, 'fobar': 456 } }; var array = [ { 'key': 'b', 'foo': 67563, 'bar': 6345, 'fobar': 3425 }, { 'key': 'c', 'foo': 34532, 'bar': 123412, 'fobar': 534532 }, { 'key': 'd', 'foo': 1234321, 'bar': 435234, 'fobar': 346457 }, { 'key': 'e', 'foo': 23523, 'bar': 124325, 'fobar': 2134235 }, { 'key': 'f', 'foo': 1235213, 'bar': 346346, 'fobar': 213423 } ];
Tests:
Array.prototype.reduce()
array.reduce(function(acc, cur) { acc[cur[key]] = cur; return acc; }, Object.assign({}, object));
_.reduce()
_.reduce(array, function(acc, cur) { acc[cur[key]] = cur; return acc; }, Object.assign({}, object));
_.reduce() with _.get()
_.reduce(array, function(acc, cur) { acc[_.get(cur, key)] = cur; return acc; }, Object.assign({}, object));
_.keyBy()
Object.assign({}, object, _.keyBy(array, key));