Skip to content

Instantly share code, notes, and snippets.

@speto
Last active May 2, 2016 13:49
Show Gist options
  • Save speto/b5f571d356e1f2bdb70ef7adb0f8e816 to your computer and use it in GitHub Desktop.
Save speto/b5f571d356e1f2bdb70ef7adb0f8e816 to your computer and use it in GitHub Desktop.
Stopwatch inspired by https://tracy.nette.org/en/#toc-timing and iPhone's stopwatch for measuring duration in JS
var Stopwatch;
(function (console) {
function createWatches() {
var watches = {};
function start(label) {
label = label || "";
watches[label] = new Date().getTime();
}
function lap(label) {
label = label || "";
if (typeof watches[label] === "undefined") {
start(label);
}
return new Date().getTime() - watches[label];
}
function log(label) {
console.log(lap(label));
}
return {
start: start,
lap: lap,
log: log
};
}
Stopwatch = createWatches();
})(console);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment