.Net: How to simulate and measure a complete web request?

I am trying to measure a query using WebRequest,

But Im gets significantly smaller results, and then measures with FireBug.

I suppose, because some materials, such as Images and CSS, are not included.

Is there a way to measure the full web request?

My code is:

public string GetPageHtmlTime(string strUrl) { WebRequest request = null; WebResponse response = null; HttpWebResponse httpCurrentWeResponse = null; try { //making a request to the file. request = WebRequest.Create(strUrl); //set 5 seconds timeout for the request request.Timeout = 5 * 1000; //Stopwatch Stopwatch sw = new Stopwatch(); sw.Start(); //get the server response response = request.GetResponse(); httpCurrentWeResponse = (HttpWebResponse)response; sw.Stop(); //if the http response return any type of failure if (httpCurrentWeResponse.StatusCode != HttpStatusCode.OK || response == null) return "Error: " + httpCurrentWeResponse.StatusCode; response.Close(); //Return time: return "OK time=" + sw.ElapsedMilliseconds.ToString("0,0"); } catch (System.Exception ex) { return "Error: ex=" + ex.Message; } } 
+4
source share
2 answers

I do not know if this is an option for you, but you can use WebBrowser , as it will request all page elements before the DocumentCompleted event DocumentCompleted .

+1
source

Your code will only measure how long it will take to complete the code, the code will not wait until all bytes appear on the client, which will take much more time.

What and where the measure depends on where you plan to optimize. If you want to improve the client experience when the server is under light load, Firebug (or Fiddler) will be a good place to measure. If you are unable to improve performance on the server when it is under heavy load, then code profilers will have the tool you need.

0
source

All Articles