简体   繁体   English

asp.net比较两个页面的性能

[英]asp.net compare two pages' performance

I have two pages and basically they show the same output but their style of programming is different. 我有两个页面,基本上它们显示相同的输出,但是它们的编程风格不同。 I want to compare the performance for these two pages like how long it takes the pages to load? 我想比较这两个页面的性能,例如页面加载需要多长时间? If we perform Submit operation then how fast is on page 1 compare to page 2 and other things. 如果我们执行Submit操作,则第1页与第2页等的速度相比要快得多。

How can I compare the performance? 如何比较效果?

Thanks in advance for your help. 在此先感谢您的帮助。

The simplest way is to set the Page trace attribute to true and observe the execution times for each of the pages event handlers, in the browser. 最简单的方法是将页面跟踪属性设置为true,并在浏览器中观察每个页面事件处理程序的执行时间。

Here's an example of a similar question: 这是一个类似问题的示例:

Measure ASP.NET page load time 测量ASP.NET页面加载时间

How long it takes to submit is one thing and another one you may want to check is the rendering time. 提交所需的时间是一件事,而您可能要检查的另一件事是渲染时间。 The simplest idea how to measure and compare performance could be writing clicking test(s) (for example with web-driver ) if you do not have them for both pages and measure how quickly test could be execute (probably running it multiple times in a sequence). 如果您在两个页面上都没有单击测试(例如,使用web-driver ),则最简单的想法是衡量其性能并进行比较(测量可能在一个程序中多次运行)。序列)。 Such approach allows you not to simple measure how much time it takes to render html itself but also how long browser loads that html (and related resource) and processes it. 通过这种方法,您不仅可以简单地测量呈现html本身所需的时间,还可以测量浏览器加载该html(及相关资源)并对其进行处理的时间。

And it's completely different story if you want to collect and aggregate performance metrics from real users which I believe out of the scope of your question. 如果您想收集和汇总来自真实用户的性能指标(我认为这超出了您的问题范围),则情况完全不同。

For the pages you are trying to time, maintain two DateTime objects dtStart and dtEnd . 对于您要计时的页面,请维护两个DateTime对象dtStartdtEnd Set dtStart to DateTime.Now in the OnPreInit method and dtEnd = DateTime.Now at the end of the Render method. OnPreInit方法dtEnd = DateTime.Now设置为DateTime.Now,在Render方法的末尾设置dtEnd dtEnd = DateTime.Now You can then calculate a TimeSpan from the two timestamps and log the time wherever you are maintaining the load times. 然后,您可以从两个时间戳计算TimeSpan,并在保持加载时间的任何地方记录时间。

On both pages, add this Trace mode: 在两个页面上,添加此跟踪模式:

<%@ Page Language="VB" Trace="True" TraceMode="SortByTime" %>

when the pages render, at the bottom of the page, you will see a dump of all the timings of each and every ASP.NET page event. 当页面呈现时,在页面底部,您将看到每个ASP.NET页面事件的所有计时的转储。 You can then see where the time difference is. 然后,您可以看到时差在哪里。

If you are interested in measuring client side rendering time, then you need to use some browser profiler. 如果您对测量客户端渲染时间感兴趣,则需要使用一些浏览器分析器。 For ex, on IE 9, hit F12, go to the Developer Tool, go to Profiler and Click Start. 例如,在IE 9上,按F12键,转到“开发人员工具”,转到“探查器”,然后单击“启动”。 Then refresh the page. 然后刷新页面。 then Stop. 然后停止。 it will then show you where the expensive javascript function is. 然后它将向您显示昂贵的javascript函数在哪里。

Google chrome and Firebug has similar tool, even more powerful. Google chrome和Firebug具有类似的工具,甚至更强大。

Helps? 有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM