Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Set union methods
Different ways to union JS Sets
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser:
Chrome 144
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 months ago
Test name
Executions per second
Spreading
717428.1 Ops/sec
Set.forEach + Set.add
709120.8 Ops/sec
Generators
604514.9 Ops/sec
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/nanoid/4.0.1/index.browser.js" integrity="sha512-YFaQHp+hWX9CMeIMngYK23kSIWaYlgsswmzmIdEw/HcK/5NLhXY2MbT0wQB5DnUzjW1uky4quIHtksukqZGkMw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Script Preparation code:
const SET_SIZE = 1000; var set1 = new Set() var set2 = new Set() while (i < SET_SIZE) { const nid = 'key:'+Math.random(); set1.add(nid); if (i % 2 == 0) set2.add(nid); i++; } while (i < SET_SIZE / 2) { set2.add('key:'+Math.random()); }
Tests:
Spreading
const set3 = new Set([...set1, ...set2]); console.log(set3.size)
Set.forEach + Set.add
const set3 = new Set(set1); set2.forEach(el => set3.add(el)); console.log(set3.size)
Generators
const set3 = new Set(function*() { yield* set1; yield* set2; }()); console.log(set3.size)