What is the performance overhead of std::function?(std::function 的性能开销是多少?)
问题描述
我在论坛上听说使用 std::function<>
会导致性能下降.这是真的吗?如果是真的,是不是性能下降很大?
I heard on a forum using std::function<>
causes performance drop. Is it true? If true, is it a big performance drop?
推荐答案
您可以从 boost 的参考资料中找到信息:通过 boost::function 调用会产生多少开销? 和 性能
You can find information from the boost's reference materials: How much overhead does a call through boost::function incur? and Performance
这并不能确定增强功能的是或否".鉴于程序的要求,性能下降可能是可以接受的.通常情况下,程序的某些部分不是性能关键的.即便如此,它也可能是可以接受的.这只能由您来确定.
This doesn't determine "yes or no" to boost function. The performance drop may be well acceptable given program's requirements. More often than not, parts of a program are not performance-critical. And even then it may be acceptable. This is only something you can determine.
对于标准库版本,标准只定义了一个接口.使其工作完全取决于个人实现.我想会使用与 boost 函数类似的实现.
As to the standard library version, the standard only defines an interface. It is entirely up to individual implementations to make it work. I suppose a similar implementation to boost's function would be used.
这篇关于std::function 的性能开销是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:std::function 的性能开销是多少?


- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- C++ 协变模板 2021-01-01