静态方法比较慢? [英] Static methods slower?
问题描述
您好,
我正在与同事(和老板)讨论在课堂上使用
静态方法。
我的同事说应该避免使用静态方法
,因为它们的使用会降低应用程序的速度。
对我来说,这听起来很荒谬 - 我相信静态方法应该在需要时使用
。但是,我无法找到任何
可靠的文件。有没有人知道一个可靠的来源
(比如微软)讨论的那个?
提前谢谢你,
$ b $bAndré
Hello,
I''m having a discussion with my colleagues (and boss) over the use of
static methods in a class.
My colleagues say that static methods should be avoided whenever is
possible, because their use slows down the application.
For me, this sounds absurd - I believe that static methods should be
used whenever they''re necessary. However, I wasn''t able to find any
reliable documents on that. Does anyone knows of a reliable source
(like Microsoft) that discusses that?
Thank you in advance,
André
推荐答案
这只是一个愚蠢的论点。并非所有方法都适用于某个实例
级别。
而不是试图证明它们是错误的,请他们证明这是静态的
方法实际上更慢。如果有的话,我认为它们会更快,因为它们不会被覆盖,也不必查看
虚拟表,IIRC。
另外,问问他们为什么他们担心方法的性能
调用,当.Net有垃圾收集,装箱/拆箱等等。
如果你在.Net中编程,你应该已经确定你不会担心纳秒的性能。如果你是,那么你需要用b或汇编代码来写你的代码..
Andy
$ b $bAndré写道:
That''s just a silly argument. Not all methods make sense at a instance
level.
Instead of trying to prove them wrong, ask them to prove that static
methods are in fact slower. If anything, I would think they are
faster, because they are not overridable and don''t have to look in a
virtual table, IIRC.
Also, ask they why they are concerned about performance of a method
call, when .Net has garbage collection, boxing / unboxing, etc.
If you''re programming in .Net, you should have already decided you''re
not going to worry about nanoseconds of performance. If you are, you
should be writing your code in C or assembly..
Andy
André wrote:
您好,
我正在与同事(和老板)讨论使用
一个类中的静态方法。
我的同事说应该避免使用静态方法
,因为它们的使用减慢了应用程序。
对我来说,这听起来很荒谬 - 我相信静态方法应该在需要时使用
。但是,我无法找到任何
可靠的文件。有没有人知道一个可靠的来源
(比如微软)讨论的那个?
提前谢谢你,
$ b $bAndré
Hello,
I''m having a discussion with my colleagues (and boss) over the use of
static methods in a class.
My colleagues say that static methods should be avoided whenever is
possible, because their use slows down the application.
For me, this sounds absurd - I believe that static methods should be
used whenever they''re necessary. However, I wasn''t able to find any
reliable documents on that. Does anyone knows of a reliable source
(like Microsoft) that discusses that?
Thank you in advance,
André
这只是一个愚蠢的论点。并非所有方法都在一个实例中有意义
That''s just a silly argument. Not all methods make sense at a instance
level。
而不是试图证明它们是错误的,请他们证明那静态
方法实际上比较慢。如果有的话,我认为它们会更快,因为它们不会被覆盖,也不必查看
虚拟表,IIRC。
另外,问问他们为什么他们担心方法的性能
调用,当.Net有垃圾收集,装箱/拆箱等等。
如果你在.Net中编程,你应该已经确定你不会担心纳秒的性能。如果你是,那么你需要用b或汇编来代码
..
level.
Instead of trying to prove them wrong, ask them to prove that static
methods are in fact slower. If anything, I would think they are
faster, because they are not overridable and don''t have to look in a
virtual table, IIRC.
Also, ask they why they are concerned about performance of a method
call, when .Net has garbage collection, boxing / unboxing, etc.
If you''re programming in .Net, you should have already decided you''re
not going to worry about nanoseconds of performance. If you are, you
should be writing your code in C or assembly..
你好,Andy,
我非常赞同你。但是,不幸的是,除非我提供一些可靠的文件(比如微软的),我就不能用我的
点了......: - (
$ b $bAndré
Hello, Andy,
I positively agree with you. But, unfortunately, unless I provide some
reliable documentation (like Microsoft''s) on that, I can''t have my
point made... :-(
André
André写道:
André wrote:
我非常赞同你。但是,不幸的是,除非我提供一些可靠的文件(如微软的),我就不能拥有我的
点制造...... :-(
I positively agree with you. But, unfortunately, unless I provide some
reliable documentation (like Microsoft''s) on that, I can''t have my
point made... :-(
我建议你继续前进,没有意义与人合作
有这么荒谬信念。
这里有一个链接,我发现实际上声称静态更快,来自
MVP ..
http://forums.microsoft.com/ MSDN / Sho ... 47372& SiteID = 1
I suggestion you move on then, no sense in working with people that
have such absurd beliefs.
Here''s one link I found that actually claims statics are faster, from
an MVP..
http://forums.microsoft.com/MSDN/Sho...47372&SiteID=1
这篇关于静态方法比较慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!