Solved

jquery how to measure response time for a server

Posted on 2013-01-18
3
1,525 Views
Last Modified: 2013-01-21
Could someone help in telling how to calculate the response time of call in jquery. Basically I need to check how long a call took from server side to respond and then capture the timing for each call made.   Some sample code is appreciated.

There is a function which lets say submit a form process it and get the response from server, and I need to capture how long it took to finish the function.  e.g.

signup.AppController.prototype.submitApplication = function(view, submission, fields) {
    view.submitting();
    controller.submission = submission;

    $.ajax({
        type: "POST",
        url: url,
        contentType: 'application/json',
        data: JSON.stringify(submission),

        complete: function(jqXHR, textStatus) {
            var response        = jqXHR.responseText ? JSON.parse(jqXHR.responseText) : {},
                status          = jqXHR.status,
                doneSubmitting  = true;
           
            if (!status) {
                // blah blah
            }

            if (doneSubmitting)
                view.doneSubmitting();
        }
    })
}
0
Comment
Question by:ysgdel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 38796249
try this


    $.ajax({
var start = new Date().getTime(); //start timer
        type: "POST",
        url: url,
        contentType: 'application/json',
        data: JSON.stringify(submission),



        complete: function(jqXHR, textStatus) {
            var response        = jqXHR.responseText ? JSON.parse(jqXHR.responseText) : {},
                status          = jqXHR.status,
                doneSubmitting  = true;
var elapsed = new Date().getTime() - start; //end timer            
            if (!status) {
                // blah blah
            }

            if (doneSubmitting)
                view.doneSubmitting();
        }
    })
}
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38796280
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 38796334
If you are asking about being able to display on the page, you need to start a timer before by creating a "start" variable with the current time and another "end" by recording the current time when the function is called.   What I gave you should be the timing from submitting the call to receiving.  It would be interesting to do the same serverside where you record the time serverside at the top of your serverside page and then again at the bottom and return the processed time.  Then in your main page you could have something like, "This process took xx milliseconds to process and xx milliseconds to load where the first number is your serverside timing and the 2nd is the js timing.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This article discusses how to create an extensible mechanism for linked drop downs.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question