Array vs Set (Large)
Date tested:
4 years ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36
Test name
Executions per second
Array
319.4 Ops/sec
Set
20741.7 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var directAddresses = []; for(var i=1; i< 100; i++) { directAddresses.push(`${i}deliverymanage@direct.com`); } var mySetDomains = new Set(); for(var i=1; i< 10000; i++) { mySetDomains.add(`${i}direct.com`); } var usingArrayDomains = []; for(var j=1; j< 10000; j++) { usingArrayDomains.push(`${j}direct.com`); }
Tests:
Array
_.map(directAddresses, (da) => { const domain = da.split('@')[1]; _.includes(usingArrayDomains, domain); });
Set
_.map(directAddresses, (da) => { const domain = da.split('@')[1]; mySetDomains.has(domain); });
Open this result on MeasureThat.net