Created
August 8, 2014 09:51
-
-
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.
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
/** | |
* 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