C++核心准则Per.5,6 关于性能的误解

面向对象思考

共 1383字,需浏览 3分钟

 ·

2020-06-20 23:45

c9a25285d5fe347c247aa93d01883f63.webp

Per.5: Don't assume that low-level code is necessarily faster than high-level code

Per.5:不要主观的认为低层次代码一定比高层次代码快


Reason(原因)

Low-level code sometimes inhibits optimizations. Optimizers sometimes do marvels with high-level code.

低层次代码有时会妨碍优化。有时优化器对高层次代码进行令人赞叹的优化。


Per.6: Don't make claims about performance without measurements

Per.6:不要只是定性抱怨性能问题


Reason(原因)

The field of performance is littered with myth and bogus folklore. Modern hardware and optimizers defy naive assumptions; even experts are regularly surprised.

性能领域的充斥者神话和虚假的传说。先进的硬件和优化器也抵挡不了无知的臆断;哪怕是专家也经常会感觉意外。


Note(注意)

Getting good performance measurements can be hard and require specialized tools.

获得好的性能度量手段很困难,需要特定的工具才行。


Note(注意)

A few simple microbenchmarks using Unix time or the standard-library  can help dispel the most obvious myths. If you can't measure your complete system accurately, at least try to measure a few of your key operations and algorithms. A profiler can help tell you which parts of your system are performance critical. Often, you will be surprised.

一些使用Unix时间的简单的基准程序或者标准库可以帮助驱散大多数明显(不实,译者注)的神话。如果你不能精确地测量整个系统,至少应该测量重要的操作和算法。分析器可以告诉你,系统的哪一部分是性能敏感的。通常,结果会让你意外的。


原文链接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#per5-dont-assume-that-low-level-code-is-necessarily-faster-than-high-level-code




觉得本文有帮助?请分享给更多人。

关注微信公众号【面向对象思考】轻松学习每一天!

面向对象开发,面向对象思考!


浏览 9
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报