Skip to content

Instantly share code, notes, and snippets.

@bigeasy
Created September 16, 2010 18:22
Show Gist options
  • Save bigeasy/582902 to your computer and use it in GitHub Desktop.
Save bigeasy/582902 to your computer and use it in GitHub Desktop.
function createCar() {
var rpms = 0;
function rev () {
rpms++;
}
return { rev: rev
};
}
function Car() {
this.rpms = 0;
}
Car.prototype.rev = function () {
this.rpms ++;
}
var start = new Date();
for (var i = 0; i < 10000; i++) {
var car = createCar();
for (j = 0; j < 10000; j++) {
car.rev();
}
}
console.log(new Date().getTime() - start.getTime());
start = new Date();
for (var i = 0; i < 10000; i++) {
var car = new Car();
for (j = 0; j < 10000; j++) {
car.rev();
}
}
console.log(new Date().getTime() - start.getTime());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment