C++核心指导原则: 性能

C++ Core Guidelines 整理目录

  1. 哲学部分
  2. 接口(Interface)部分
  3. 函数部分
  4. 类和类层次结构部分
  5. 枚举部分
  6. 资源管理部分
  7. 表达式和语句部分
  8. 性能部分
  9. 并发和并行
  10. 错误处理
  11. 常量和不可变性
  12. 泛型编程
  13. 源文件
  14. 命名和布局建议
  15. 标准库
  16. 其他规则

Per: Performance

Per.1: Don’t optimize without reason

Per.2: Don’t optimize prematurely

Per.3: Don’t optimize something that’s not performance critical

Per.4: Don’t assume that complicated code is necessarily faster than simple code

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

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

Per.7: Design to enable optimization

Per.10: Rely on the static type system

Per.11: Move computation from run time to compile time

Per.12: Eliminate redundant aliases

Per.13: Eliminate redundant indirections

Per.14: Minimize the number of allocations and deallocations

Per.15: Do not allocate on a critical branch

Per.16: Use compact data structures

Per.17: Declare the most used member of a time-critical struct first

Per.18: Space is time

Per.19: Access memory predictably

Per.30: Avoid context switches on the critical path