Created
September 16, 2010 18:22
-
-
Save bigeasy/582902 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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