views:

479

answers:

2

If my goal is to test the rendering speed in IE of a specific web page through repeated loads (merely using a javascript onload event for timing and viewing the page doesn't cut it), what would be a good way to do it?

My current attempt was by using the IE WebBrowser object in VB and C#, though I'm open to other suggestions.

Below is some simple VB code, though I've tried something similar in C#. I've also tried creating a new web browser control for each test (this made things worse). I've also tried using the events themselves rather than using a readystate loop. In all cases, the tests take longer and longer to run, though using reload complete instread of navigate2 seems to help a little, perhaps implying the problem is some sort of history issue.

For cnt = 1 To 100
    timer = GetTickCount()
    Form1.WebBrowser1.Navigate2 "http://www.example.com"
    While Form1.WebBrowser1.ReadyState <> READYSTATE_COMPLETE And GetTickCount() - timer < 5000
        Sleep 50
        DoEvents
    Wend
    Debug.Print GetTickCount() - timer
Next
A: 

I think a better approach would be to handle the OnBeforeNavigate and OnDocumentComplete events that the Webbrowser control exposes. Set a timer in OnBeforeNavigate and stop it in OnDocumentComplete.

Right now you are busy-waiting, which is never a good idea.

jeffamaphone
As mentioned in my post, I already tried that and it did not help. I posted this specific example because it is the simplest way to reproduce the problem, not because it is the best.
Brian
Actually, the event-based approach is what I tried first. This was a much later attempt to solve the problem. My hope was that the added simplicity would reduce the complexity, thus either removing the issue or at least pinpointing it.
Brian
A: 

I'm not sure what events you can hook on the control for start and finish, but here is the code i used in my unit test to do the calculation of how long my Engine took to process the data I gave it.

Stopwatch stopWatch = new Stopwatch();

stopWatch.Start();
//perform work
stopWatch.Stop();

TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                           ts.Hours,
                                           ts.Minutes,
                                           ts.Seconds,
                                           ts.Milliseconds/10);
Console.Write(elapsedTime);

Cheers!

Chris