测试特定页面上IE的呈现速度

时间:2022-02-19 11:32:49

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?

如果我的目标是通过重复加载来测试特定网页的IE中的渲染速度(仅仅使用javascript onload事件进行计时并且查看页面不会削减它),那么这样做的好方法是什么?

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

我目前的尝试是在VB和C#中使用IE WebBrowser对象,尽管我对其他建议持开放态度。

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.

下面是一些简单的VB代码,虽然我在C#中尝试了类似的东西。我也尝试为每个测试创建一个新的Web浏览器控件(这使事情变得更糟)。我也尝试过使用事件而不是使用readystate循环。在所有情况下,测试运行时间越来越长,尽管使用reboot2的重载完整instread似乎有点帮助,也许暗示问题是某种历史问题。

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

2 个解决方案

#1


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.

我认为更好的方法是处理Webbrowser控件公开的OnBeforeNavigate和OnDocumentComplete事件。在OnBeforeNavigate中设置一个计时器并在OnDocumentComplete中将其停止。

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

现在你正在忙着等待,这绝不是一个好主意。

#2


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!

#1


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.

我认为更好的方法是处理Webbrowser控件公开的OnBeforeNavigate和OnDocumentComplete事件。在OnBeforeNavigate中设置一个计时器并在OnDocumentComplete中将其停止。

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

现在你正在忙着等待,这绝不是一个好主意。

#2


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!