Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Set vs Object vs Lodash union: Add items to unique array
Union an array or 1 million items with an array of 2 million items, 1 million of which are duplicates.
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
Set
1.5 Ops/sec
Object
1.5 Ops/sec
Lodash union
1.3 Ops/sec
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
Script Preparation code:
var origNumItems = 1000000; // 1 million var newNumItems = origNumItems * 2; var origArr = []; var newItems = []; function initArray(arr, numItems) { for (var i = 0; i <= numItems; i++) { arr.push(`Item ${i}`); } } initArray(origArr, origNumItems); initArray(newItems, newNumItems);
Tests:
Set
var s = new Set(origArr); for (const i in newItems) { s.add(i); } Array.from(s);
Object
var obj = {}; for (const i in origArr) { obj[i] = true; } for (const i in newItems) { obj[i] = true; } _.keys(obj)
Lodash union
// Creating this duplicate array is needed to emulate creating the data structure that contains the new items, // which the other tests do by creating an object or set var newArr = []; for (const i in newItems) { newArr.push(i); } _.union(origArr, newArr)