Last active
May 2, 2016 13:49
-
-
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
This file contains 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
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