Skip to content

Instantly share code, notes, and snippets.

@williampsena
Created March 10, 2020 14:54
Show Gist options
  • Save williampsena/78d6fe2d366f0e886be3baf6856140a8 to your computer and use it in GitHub Desktop.
Save williampsena/78d6fe2d366f0e886be3baf6856140a8 to your computer and use it in GitHub Desktop.
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