C++核心准则Per.5,6 关于性能的误解
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
新书介绍
以下是本人3月份出版的新书,拜托多多关注!
本书利用Python 的标准GUI 工具包tkinter,通过可执行的示例对23 个设计模式逐个进行说明。这样一方面可以使读者了解真实的软件开发工作中每个设计模式的运用场景和想要解决的问题;另一方面通过对这些问题的解决过程进行说明,让读者明白在编写代码时如何判断使用设计模式的利弊,并合理运用设计模式。
对设计模式感兴趣而且希望随学随用的读者通过本书可以快速跨越从理解到运用的门槛;希望学习Python GUI 编程的读者可以将本书中的示例作为设计和开发的参考;使用Python 语言进行图像分析、数据处理工作的读者可以直接以本书中的示例为基础,迅速构建自己的系统架构。
觉得本文有帮助?欢迎点赞并分享给更多的人。
阅读更多更新文章,请关注微信公众号【面向对象思考】