Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

In c# windows project, I am passing URL & want to know -
1) Time taken to load page.
Code I am using -
C#
Stopwatch sw = new Stopwatch();
   HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.abc.com/");
   sw.Start();
   HttpWebResponse res = (HttpWebResponse)req.GetResponse();
   sw.Stop(); 
string  timeToLoad = sw.Elapsed.TotalSeconds.ToString();

Is it correct? or any better way?

2) How to calculate the load time of external js that's been used in this page.

Thanks
Posted
Updated 9-Dec-11 2:04am
v3
Comments
Sergey Alexandrovich Kryukov 8-Dec-11 12:05pm    
JavaScript? ASP.NET? Tag the question correctly, hard to see what is it about.
--SA
anushripatil 9-Dec-11 5:21am    
ITS c# windows project ... as mentioned

The method given will only get the html page but won't resolve and load additional resources like javascript, css, images etc... It is also very hard to figure out the actual load time of a page when dynamic content is added with javascript. In some cases you would actually need to execute the javascript to resolve them.

There are also browser dependent implementation factors that are almost impossible to know. Different browsers and also browser versions implement different load schemes for loading some resources in-order and others concurrently. This is something which is virtually impossible to implement but has a great influence on the page load time.

The best way would be to measure it using different browsers and use a tool like YSlow[^] which can plug-in to most commonly used browsers. They also give tips on how to improve load performance by the way.

Another option would be to use browser controls of different browsers and use those to measure load performance. Instead of adding a plug-in to the browser you would be using different browsers as kind of plug-ins for your application.
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx[^]
http://code.google.com/p/geckofx/[^]
https://github.com/chillitom/CefSharp[^]

Good luck!

More tools:http://www.softwareqatest.com/qatweb1.html[^]
 
Share this answer
 
v2
Comments
Monjurul Habib 9-Dec-11 15:18pm    
5!
E.F. Nijboer 10-Dec-11 9:37am    
Thanks :-)
anushripatil 12-Dec-11 6:16am    
Thanks for your reply.
I have 1 more solution,
1)For Time taken to load page , using browser.Navigate("MYURL") then starting the stopwatch & in documentcompleted doing stop.
2) for load time of external js
WebRequest req = HttpWebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
& getting resp.Headers.Get("Content-Length")
This both gives me the same result as fiddler or Yslow or Pagespeed gives.
Thanks for your help :)
1)For Time taken to load page , using browser.Navigate("MYURL") then starting the stopwatch & in documentcompleted doing stop.
2) for load time of external js
WebRequest req = HttpWebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
& getting resp.Headers.Get("Content-Length")
This both gives me the same result as fiddler or firebug gives.
Thanks for your help :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900