是否使用委托放慢我的.NET程序? [英] Does using delegates slow down my .NET programs?

查看:128
本文介绍了是否使用委托放慢我的.NET程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否使用委托减缓我的程序?

Does using delegates slow down my programs?

我一直在回避他们,因为我真的不知道,如果他们让我的任何计划要慢。我知道,如果我造成(捕获)异常,使用相当多的CPU处理能力,但我不知道委托和事件,什么.NET确实给他们。

I've been avoiding them because I really have no clue if they make my programs any slower. I know if I cause a (catch) exception, that uses quite a bit of CPU power but I don't know about Delegates and Events and what .NET does to them.

推荐答案

代表们都非常,非常快。不太一样快,直接的方法调用,但为期不远了。他们成为瓶颈的机会是微乎其微的。

Delegates are very, very fast. Not quite as fast as direct method calls, but not far off. The chances of them becoming a bottleneck are miniscule.

(同样例外,如果使用得当,实际上很少会导致性能问题。 )

(Likewise exceptions, when used properly, rarely actually cause a performance issue.)

会使用委托让你的code更简单,更易读,更强大的?如果是这样,使用它们。仔细衡量你的表现,并保持它的眼睛。远离可读性为求表现,只有当数据是明确的。

Would using delegates make your code simpler, more readable, and more robust? If so, use them. Measure your performance carefully, and keep an eye on it. Move away from readability for the sake of performance only when the data is clear.

我敢肯定有各地的代表展示的速度VS接口与非虚方法调用等一些图表 - 我不知道他们在哪里,但你总是可以运行测试自己,如果你真的很担心。

I'm sure there are some graphs around showing the speed of delegates vs interfaces vs non-virtual method calls etc - I don't know where they are, but you could always run tests yourself if you're really worried.

这篇关于是否使用委托放慢我的.NET程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆