Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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