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 的性能开销是多少?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
