Skip to content

Instantly share code, notes, and snippets.

@chrislaughlin
Last active February 6, 2020 23:17
Show Gist options
  • Save chrislaughlin/90ac6fed9d3027f7d382ce6922ebfbc2 to your computer and use it in GitHub Desktop.
Save chrislaughlin/90ac6fed9d3027f7d382ce6922ebfbc2 to your computer and use it in GitHub Desktop.
let testArray = Array(1000000).fill().map((_, i) => i * i);
let testMap = new Map();
testArray.forEach(item => testMap.set(item, item));
const find = () => {
console.time('Array find');
testArray.find(val => val == 9604)
console.timeEnd('Array find');
};
const getFromMap = () => {
console.time('Map get');
testMap.get(9604);
console.timeEnd('Map get');
}
find();
find();
find();
console.log('-------------')
getFromMap();
getFromMap();
getFromMap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment