Checking response time with HTTPWebRequest

If you want to time the response time of your webrequests/proxies, etc using C# there is a easy way to do it. We need to use a stopwatch object as shown in the example.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);
System.Diagnostics.Stopwatch timer = new Stopwatch();

timer.Start();

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

timer.Stop();

TimeSpan timeTaken = timer.Elapsed;

Leave a Reply

Your email address will not be published. Required fields are marked *