Skip to content

Instantly share code, notes, and snippets.

@JobLeonard
Last active December 16, 2024 14:25
Show Gist options
  • Save JobLeonard/13fdee246e928ee75c181138744178b0 to your computer and use it in GitHub Desktop.
Save JobLeonard/13fdee246e928ee75c181138744178b0 to your computer and use it in GitHub Desktop.
Set.has vs Map.get
{"title":"Set.has vs Map.get","initialization":"// runs once\nconst keys = [];\nlet map, set;\nconst results = new Uint8Array(1000);","setup":"for (let i = 0; i < 100; i++) {\n keys[i] = Math.random() * 1000 | 0;\n}\nmap = new Map(keys.map(k => [k, true]));\nset = new Set(keys);","tests":[{"name":"Set.has","code":"for (let i = 0; i < 1000; i++) {\n results[i] = set.has(i) ? 1 : 0;\n}","results":{"aborted":false,"count":15016,"cycles":5,"hz":170163.33944555596,"stats":{"moe":1.1161958284943126e-7,"rme":1.899356096517913,"sem":5.694876675991391e-8,"deviation":4.2995376033020027e-7,"mean":0.000005876706482479157,"variance":1.848602360220793e-13,"numSamples":57},"times":{"cycle":0.08824462454090702,"elapsed":5.952,"period":0.000005876706482479157,"timeStamp":1734359102734}},"platforms":{"Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0":{"aborted":false,"count":15016,"cycles":5,"hz":170163.33944555596,"stats":{"moe":1.1161958284943126e-7,"rme":1.899356096517913,"sem":5.694876675991391e-8,"deviation":4.2995376033020027e-7,"mean":0.000005876706482479157,"variance":1.848602360220793e-13,"numSamples":57},"times":{"cycle":0.08824462454090702,"elapsed":5.952,"period":0.000005876706482479157,"timeStamp":1734359102734}},"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36":{"aborted":false,"count":9564,"cycles":4,"hz":111557.90488597131,"stats":{"moe":1.1790330729214552e-7,"rme":1.3153045940638617,"sem":6.01547486184416e-8,"deviation":4.659566791890359e-7,"mean":0.000008963954647787156,"variance":2.1711562688087413e-13,"numSamples":60},"times":{"cycle":0.08573126225143636,"elapsed":5.817,"period":0.000008963954647787156,"timeStamp":1734358878543}}}},{"name":"Map.get","code":"for (let i = 0; i < 1000; i++) {\n results[i] = map.get(i) ? 1 : 0;\n}","results":{"aborted":false,"count":14117,"cycles":4,"hz":163531.0226773999,"stats":{"moe":1.2207771136185756e-7,"rme":1.9963492985121005,"sem":6.228454661319263e-8,"deviation":4.824540235179492e-7,"mean":0.000006115047674915573,"variance":2.327618848086579e-13,"numSamples":60},"times":{"cycle":0.08632612802678315,"elapsed":5.764,"period":0.000006115047674915573,"timeStamp":1734359108691}},"platforms":{"Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0":{"aborted":false,"count":14117,"cycles":4,"hz":163531.0226773999,"stats":{"moe":1.2207771136185756e-7,"rme":1.9963492985121005,"sem":6.228454661319263e-8,"deviation":4.824540235179492e-7,"mean":0.000006115047674915573,"variance":2.327618848086579e-13,"numSamples":60},"times":{"cycle":0.08632612802678315,"elapsed":5.764,"period":0.000006115047674915573,"timeStamp":1734359108691}},"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36":{"aborted":false,"count":14983,"cycles":6,"hz":178747.38378951352,"stats":{"moe":6.688368310971464e-8,"rme":1.1955283374068366,"sem":3.412432811720135e-8,"deviation":2.6432590899687664e-7,"mean":0.000005594487476121966,"variance":6.986818616702511e-14,"numSamples":60},"times":{"cycle":0.08382220585473542,"elapsed":6.003,"period":0.000005594487476121966,"timeStamp":1734358884366}}}}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment