How to measure response time and web page load time?

I need to create a Windows forms application to measure the time it takes to fully load a web page, and what is the best way to do this?

The purpose of this small application is to track some pages on a website for a certain period of time, in order to be able to know in advance if something is wrong with the web server or database server.

Additional Information:

I can’t use a commercial application, I need to develop it in order to be able to save the results in a database and create a series of reports based on this information.

The webrequest solution is similar to the approach I use to use, however it would be nice to measure the time it takes to fully load the page (images, css, javascript, etc.). Any idea how this can be done?

+5
source share
9 answers

If you just want to record how long it takes to get the main source of the page, you can wrap the HttpWebRequest around the stopwatch. For example.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

System.Diagnostics.Stopwatch timer = new Stopwatch();
timer.Start();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

timer.Stop();

TimeSpan timeTaken = timer.Elapsed;

However, this will not take into account the loading time of additional content, such as images.

[] WebBrowser .Navigate() DocumentCompleted . , . , WebBrowser , , .

+16

, , , Selenium ( -), - . , Selenium API .Net ( Selenium ).

, - , - (JS, CSS, , iframe ..) - (http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309/).

, , ( , html, ).

+3

, , - . , , . , .

. , 9:00 15 , 9:05, 3 , , , 10:00 15 .

, , 9 , . 9:05 , . , 10 , .

YSlow addin FireFox, , .

+2

- , , :

System.Diagnostics.Stopwatch sw = new Stopwatch()
System.Net.HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.example.com");
// other request details, credentials, proxy settings, etc...

sw.Start();
System.Net.HttpWebResponse res = (HttpWebResponse)req.GetResponse();
sw.Stop();

TimeSpan timeToLoad = sw.Elapsed;
+1

, HTML- , (, ..).

, , HTTP-, - SVG PNG , . <object>.

+1

. : -, ? , , , 2 2 , , . , , , ( ). : , ? - p2p, , - , -, , . , -? , , , , , ?

/ , ? , PHP:

function microtime_float()
{
  list($usec, $sec) = explode(" ", microtime());
  return ((float)$usec + (float)$sec);
}

function benchmark($finish)
{
  if($finish == FALSE){  /* benchmark start*/    
    $GLOBALS["time_start"] = microtime_float();
  }else{ /* benchmark end */    
    $time = microtime_float() - $GLOBALS["time_start"]; 
    echo '<div id="performance"><p>'.$time.'</p></div>';
  }
}

, ( css). . , , - ( !) RSS- , .

firebug , "" ( ). ( ). . ? , / . . ping IP-, , . , -, ...

+1
0
source

If you are using firefox, install the firebug extension found at http://getfirebug.com . From there, select the net tab, and it will tell you the download / response time for everything on the page.

0
source

All Articles