Skip to content

Instantly share code, notes, and snippets.

@shubhadeep
Created August 8, 2014 09:51
Show Gist options
  • Save shubhadeep/371f9245656d5937af09 to your computer and use it in GitHub Desktop.
Save shubhadeep/371f9245656d5937af09 to your computer and use it in GitHub Desktop.
Creating empty objects in different ways and checking execution time, heap size etc.
/**
* Creating empty objects in different ways and checking execution time, heap size etc.
*/
// Property-less object
console.time('zoop');
var zoop = (function (numObjects) {
var pooz = Object.create(null);
for(var i = 0; i< numObjects; i++) {
pooz[i] = Object.create(null);
}
return pooz;
})(1000000);
console.timeEnd('zoop');
// Using Object Literal
console.time('zoop');
var zoop = (function (numObjects) {
var pooz = {};
for(var i = 0; i< numObjects; i++) {
pooz[i] = {};
}
return pooz;
})(1000000);
console.timeEnd('zoop');
// Object.create({})
console.time('zoop');
var zoop = (function (numObjects) {
var pooz = Object.create({});
for(var i = 0; i< numObjects; i++) {
pooz[i] = Object.create({});
}
return pooz;
})(1000000);
console.timeEnd('zoop');
// new Object
console.time('zoop');
var zoop = (function (numObjects) {
var pooz = new Object();
for(var i = 0; i< numObjects; i++) {
pooz[i] = new Object();
}
return pooz;
})(1000000);
console.timeEnd('zoop');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment