如何测量 WPF Silverlight FPS 或渲染时间?
我有一个控件(适用于 WPF 和 Silverlight),将数据表示为条形。 (小图表)。我想编写一个应用程序来测量该控件的性能。我尝试在循环中添加点并等待点被渲染。
在WPF中工作是这样的:
//start measuring time
for (int i =10, i<100, i++){
chart.AddRandomPoint(i); //i - argument
System.Windows.Forms.Application.DoEvents();
}
//finish measuring time
但是在Silverlight中不可能使用System.Windows.Forms.Application.DoEvents()。
第二种方法是使用 DispatcherTimer:
dicpatcherTimer_Tick(object sender, EventArgs e){
chart.AddRandomPoint(i);
}
并订阅 CompositionTarget.Rendering 事件。在事件处理程序中 icrement 计数器。 该计数器的大值表明其具有良好的性能。
我的问题是: 是否可以添加点,等待图表渲染,立即添加另一个点等?
第二种方法(使用 DispatcherTimer 对象和 CompositionTarget.Rendering 事件)是否正确。能体现性能吗? (我需要比较重构前后的性能)。
I have a control (for both WPF and Silverlight), represented data as bars. (Small chart). I want write an application, that measure performance of this control. I try to add points in cycle and wait while point will be rendered.
In WPF work this:
//start measuring time
for (int i =10, i<100, i++){
chart.AddRandomPoint(i); //i - argument
System.Windows.Forms.Application.DoEvents();
}
//finish measuring time
But in Silverlight it's impossible to use System.Windows.Forms.Application.DoEvents().
The second way is using DispatcherTimer:
dicpatcherTimer_Tick(object sender, EventArgs e){
chart.AddRandomPoint(i);
}
and subscribe to CompositionTarget.Rendering event. In event handler icrement counter.
Big value of this counter shows good performance.
My question is:
It is possible add point, wait while chart will be rendered, immediately add another one point etc.?
Is the second way (using DispatcherTimer object and CompositionTarget.Rendering event) correct. Can it shows performance? (I need to compare performance before and after refactoring).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑到您太询问WPF,我建议您查看
WPF 性能工具包,特别认为Perforator会给你很多帮助有了这个。
关于 WPF/Silverlight 性能的好文章是 深入探讨 WPF 渲染系统
Considering that you'are asking about WPF too, I would suggest to look at
WPF Performance Toolkit, especially think that Perforator will help you a lot with this.
Good article on WPF/Silverlight performance is A Critical Deep Dive into the WPF Rendering System