Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

measure processing time of AJAX call

Tags:

javascript

I want to measure how long it takes to process AJAX call. I have it up and running but don't know how to code this in javascript (js only)

like image 721
Radek Avatar asked Mar 03 '11 06:03

Radek


People also ask

How do I get AJAX response time?

The most simple method would be to add var ajaxTime= new Date(). getTime(); before the Ajax call and in the done get the current time to calculate how long the Ajax call took to make. var ajaxTime= new Date(). getTime(); $.

Are AJAX calls slow?

In sites that rely upon Ajax for functionality (or even pizzazz), performance becomes even more critical than the general JavaScript performance. Because Ajax requests take place behind the scenes, to the end user there is little discernible difference between an Ajax request being slow, and nothing happening at all.

How do I know when AJAX calls are complete?

The ajaxStop() method specifies a function to run when ALL AJAX requests have completed. When an AJAX request completes, jQuery checks if there are any more AJAX requests. The function specified with the ajaxStop() method will run if no other requests are pending.


1 Answers

var start = new Date().getTime();
doAjax({
  success: function() {
    var end = new Date().getTime();
    console.log('milliseconds passed', end - start);
  }
});

save a time value before you start doing ajax stuff, and then do it again when it finishes. Then subtract one form the other and get your time.

like image 181
Alex Wayne Avatar answered Oct 19 '22 04:10

Alex Wayne