To time and measure the duration of a JavaScript event.
function start() {
startTime = new Date().getTime();
}
function stop() {
var endTime = new Date().getTime();
return endTime - startTime;
}
Example:
function start() {
startTime = new Date().getTime();
}
function stop() {
var endTime = new Date().getTime();
return endTime - startTime;
}
function doSomething() {
for (var i = 0; i < 1000000; i++) {
// Do something
}
}
<input value="Click me" onclick="start(); doSomething(); alert(stop() + 'ms');" type="button" />
Comments
Leave a Reply