虚拟函数和性能 - C ++ [英] Virtual functions and performance - C++
问题描述
在我的类设计中,我广泛使用抽象类和虚拟函数。我有一种感觉,虚拟功能影响性能。这是真的?但我认为这种性能差异不明显,看起来像我做过早优化。对吗?
In my class design, I use abstract classes and virtual functions extensively. I had a feeling that virtual functions affects the performance. Is this true? But I think this performance difference is not noticeable and looks like I am doing premature optimization. Right?
推荐答案
一个好的经验法则是:
这不是一个性能问题,直到你可以证明。
It's not a performance problem until you can prove it.
使用虚拟函数将有一个非常轻微的对性能的影响,但不会影响应用程序的整体性能。更好的地方寻找性能改进是在算法和I / O。
The use of virtual functions will have a very slight effect on performance, but it's unlikely to affect the overall performance of your application. Better places to look for performance improvements are in algorithms and I/O.
一个很好的文章谈论虚拟函数(和更多)是成员函数指针和最快的C ++代理。
An excellent article that talks about virtual functions (and more) is Member Function Pointers and the Fastest Possible C++ Delegates.
这篇关于虚拟函数和性能 - C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!