var start, stop, elapsedMilliseconds; start = new Date(); someProcess(); stop = new Date(); elapsedMilliseconds = stop.getTime() - start.getTime(); document.write(elapsedMilliseconds + " Milliseconds have passed");
However, there’s a simpler way:
var start, stop; start = +new Date(); someProcess(); stop = +new Date(); document.write(stop-start + " Milliseconds have passed");
When you add the plus-sign infront of the
new operator, the date returned is automatically converted into a timestamp allowing you to quickly assess the amount of milliseconds that have passed.