Skip to content

Instantly share code, notes, and snippets.

@papandreou
Created August 2, 2011 12:00
Show Gist options
  • Save papandreou/1120060 to your computer and use it in GitHub Desktop.
Save papandreou/1120060 to your computer and use it in GitHub Desktop.
new Object vs. {} benchmark
function benchmark() { // ...
for (var i = 0 ; i < arguments.length ; i += 1) {
var startTime = new Date(),
fn = arguments[i];
for (var j = 0 ; j < 10000000 ; j += 1) {
fn();
}
console.warn(arguments[i].name + ": " + ((new Date().getTime() - startTime) / 1000).toFixed(3));
}
}
function newObject() {
var a = new Object;
}
function objectLiteral() {
var a = {};
}
benchmark(newObject, objectLiteral);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment