问题描述
我也接触过很多的优化技巧,这也就是说,作为密封,以获得额外的性能优势,您应该标记你的类。
I have come across a lot of optimization tips which say that you should mark your classes as sealed to get extra performance benefits.
我进行了一些测试,以检查性能差和没有发现。难道我做错了什么?我缺少的情况下,密封类会给出更好的结果?
I ran some tests to check the performance differential and found none. Am I doing something wrong? Am I missing the case where sealed classes will give better results?
有没有人进行测试,看到有区别吗?
Has anyone run tests and seen a difference?
帮助我学习:)
推荐答案
抖动有时会使用密封类非虚拟调用方法,因为没有办法,他们可以进一步扩大。
The JITter will sometimes use non-virtual calls to methods in sealed classes since there is no way they can be extended further.
有关于呼叫类型,虚拟/非虚复杂的规则,我不知道他们所有的,所以我真的不能勾勒出他们为你,但是如果你谷歌的密封类和虚拟方法,你可能在找一些文章主题。
There are complex rules regarding calling type, virtual/nonvirtual, and I don't know them all so I can't really outline them for you, but if you google for sealed classes and virtual methods you might find some articles on the topic.
请注意,任何一种性能优势,你会从优化这个层面得到应被视为最后手段,总是在算法级优化您优化的code级之前。
Note that any kind of performance benefit you would obtain from this level of optimization should be regarded as last-resort, always optimize on the algorithmic level before you optimize on the code-level.
这里有一个链接提到这一点:<一href="http://$c$cbetter.com/blogs/patricksmacchia/archive/2008/01/05/rambling-on-the-sealed-keyword.aspx">Rambling在密封的关键字
Here's one link mentioning this: Rambling on the sealed keyword
这篇关于难道密封类提供真正的性能优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!