Last active
May 7, 2016 23:32
-
-
Save yeion7/b4613ba0a72d4a8017cae372cce176d2 to your computer and use it in GitHub Desktop.
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
// Constructor test | |
function constructor() { }; | |
function constructorTest(N) { | |
var start = Date.now(); | |
for (var i = 0; i < N; i++) { | |
new constructor(); | |
} | |
return (Date.now() - start) / N; | |
} | |
// Factory test | |
function factory() { | |
return { }; | |
}; | |
function factoryTest(N) { | |
var start = Date.now(); | |
for (var i = 0; i < N; i++) { | |
new constructor(); | |
} | |
return (Date.now() - start) / N; | |
} | |
// literal test | |
// | |
function literalTest(N) { | |
var start = Date.now(); | |
for (var i = 0; i < N; i++) { | |
{} | |
} | |
return (Date.now() - start) / N; | |
} | |
console.log('Constructor Objects: ', constructorTest(1e6)); | |
console.log('Factory Objects: ', factoryTest(1e6)); | |
console.log('Literal Objects: ', literalTest(1e6)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment