Created
January 25, 2012 18:41
-
-
Save jeffreyiacono/1677822 to your computer and use it in GitHub Desktop.
a simple pace car to test how fast (or slow) your js runs
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
/** | |
* PaceCar makes it easy to test how fast (or slow) you js runs | |
* | |
* Example Usage: | |
* | |
* // get a PaceCar ready | |
* var p = new PaceCar(); | |
* // start your engines | |
* p.start(); | |
* // some sample code you want to test performance of. | |
* // who doesn't like to loop for no reason? | |
* for (var i=0; i < 10000; i=i+1) { | |
* $('body').html('hi'); | |
* } | |
* // stop the pacecar and print the execution time in ms | |
* p.stop(); // => 79ms | |
*/ | |
;(function(exports) { | |
"use strict"; | |
function PaceCar() { | |
return this; | |
} | |
PaceCar.prototype.start = function() { | |
this._start = (new Date()).getTime(); | |
}; | |
PaceCar.prototype.stop = function() { | |
window.console.log(((new Date()).getTime() - this._start) + ' ms'); | |
}; | |
exports.PaceCar = PaceCar; | |
}(this)); // <-- this = the global object is passed as exports |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment