如何测量 WPF Silverlight FPS 或渲染时间?

发布于 2025-01-05 12:39:06 字数 744 浏览 1 评论 0原文

我有一个控件(适用于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风尘浪孓 2025-01-12 12:39:07

考虑到您询问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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文