This will not give exact timings because javascript uses an event queue . This means that your program can run as follows:
- Run an AJAX request
- Handle the pending mouse click event / any other code wait string in the meantime
- Start processing an AJAX response
Unfortunately, there is no way to get the time when the event was added to the queue, as far as I know. Event.timeStamp returns the time when the event was pushed out of the queue, see this script: http://jsfiddle.net/mSg55/ .
Html:
<a href="#">link</a> <div></div>
JavaScript:
$(function() { var startTime = new Date(); $('a').click(function(e) { var endTime = new Date(e.timeStamp); $('div').append((endTime - startTime) + " ");
Aristoteles Jul 03 '14 at 10:42 on 2014-07-03 10:42
source share