Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created January 25, 2012 18:41
Show Gist options
  • Save jeffreyiacono/1677822 to your computer and use it in GitHub Desktop.
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
/**
* 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