Created
March 10, 2020 14:54
-
-
Save williampsena/78d6fe2d366f0e886be3baf6856140a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomString() | |
{ | |
var text = ""; | |
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | |
for( var i=0; i < 5; i++ ) | |
text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
return text; | |
} | |
function getRandomRange (min, max) { | |
return Math.floor(Math.random() * (+max - +min) + +min) | |
} | |
var values = [] | |
var attrs ={} | |
for(var i=0; i<100000; i++) { | |
const key = randomString() | |
values.push(key) | |
attrs[key] = true | |
} | |
var filters = [] | |
for(var i=0; i<1000; i++) { | |
filters.push(values[getRandomRange(0, 100000)]) | |
} | |
console.time('includes') | |
filters.map(filter => | |
values.includes(filter) | |
) | |
console.timeEnd('includes') | |
console.time('map') | |
filters.map(filter => | |
!!attrs[filter] | |
) | |
console.timeEnd('map') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment