Skip to content

Instantly share code, notes, and snippets.

@tofusoup429
Created December 4, 2020 03:03
Show Gist options
  • Save tofusoup429/02534ab82530d7aa228548adada249ff to your computer and use it in GitHub Desktop.
Save tofusoup429/02534ab82530d7aa228548adada249ff to your computer and use it in GitHub Desktop.
const objectMaker = (_size)=>{
//create an object with size of _size
let obj = {}
for(let i=0; i<_size; i++){
obj[i.toString()] = i
}
return obj
}
const mapMaker = (_size)=>{
//create a map with size of _size
let map = new Map();
for(let i=0; i<_size; i++){
map.set(i.toString(), i)
}
return map
}
const checkInterval = (cb) => {
//checkInterval in millionth second of conducting callback
let beginning = Date.now();
cb()
let ending = Date.now();
return ending-beginning
}
let obj1 = objectMaker(100000);
let map1 = mapMaker(100000);
let obj1Time = checkInterval(()=>{
//measuring elapsed time of getting size of an object
console.log('object size', Object.keys(obj1).length )
return Object.keys(obj1).length;
})
let map1Time = checkInterval(()=>{
//measuring elapsed time of getting size of an map
console.log('map size', map1.size)
return map1.size
});
console.log('map1Time', map1Time);
console.log('obj1Time', obj1Time);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment