Skip to content

Instantly share code, notes, and snippets.

@amakhrov
Created December 3, 2012 19:52
Show Gist options
  • Save amakhrov/4197504 to your computer and use it in GitHub Desktop.
Save amakhrov/4197504 to your computer and use it in GitHub Desktop.
timer for profiling
var timer = {
start: function (s) {
this.stop();
this.name = s;
this.startts = Date.now();
},
stop: function () {
if (!this.name) return;
this.endts = Date.now();
this.diff = (this.endts - this.startts) / 1000;
this.print();
this.name = '';
},
print: function () {
log(this.name + ' duration: ' + this.diff);
}
};
timer.start('some process');
timer.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment