std::function 的性能开销是多少?

What is the performance overhead of std::function?(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 的性能开销是多少?

基础教程推荐