前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则Per.5,6 关于性能的误解

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

作者头像
面向对象思考
发布2020-06-24 10:43:09
3120
发布2020-06-24 10:43:09
举报

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

原文链接

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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-06-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Per.5: Don't assume that low-level code is necessarily faster than high-level code
  • Reason(原因)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档