Skip to content

Instantly share code, notes, and snippets.

@yeion7
Last active May 7, 2016 23:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yeion7/b4613ba0a72d4a8017cae372cce176d2 to your computer and use it in GitHub Desktop.
// 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