简体   繁体   中英

How can I get the total server AND client page load time?

I am measuring performance of an ASP.NET page. I need to measurement two parts: 1) The server page load time (to calculate the time it takes to bind controls from data loaded from database) and 2) measure the difference between the millisecond that the server's PageLoad event started and the millisecond that the client has finished loading (because I want to be able to calculate the time it took for the client browser to download and render the HTML).

Measuring the serverside load time is easy with the StopWatch class. The part I need advice for is capturing the date and time that the client has loaded.

Here's what I am doing in this order:

  • As soon as server page load event runs, I write the current date and time to a hidden field.
  • On the client, I use $(document).ready() to fire off an AJAX call to a WebMethod that returns the server's date and time.
  • I then parse the dates and times from the date string stored in the hidden field and the date string returned from the Webmethod call and write their differences to a span element on the page.

I do this so I can keep the client datetime in sync with the server datetime due to the fact that someone's machine time can easily be off by a few seconds. However, I think that AJAX call adds a little overhead itself which is counterproductive to performance measurement.

Is there an accurate method of using GMT to sync up the client time with the server time without having to report to the server to get it?

About the server side, you can set Trace=true in Page directive

http://msdn.microsoft.com/en-us/library/94c55d08(v=vs.100).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM