《C++性能优化指南》

本文总结了C++代码优化策略,包括使用高性能编译器、优化算法、利用更好库、减少内存操作等,并探讨了内存访问速度、对齐问题等影响优化的计算机行为,旨在提升程序在嵌入式、移动和服务器环境中的性能。
摘要由CSDN通过智能技术生成

优化是一门实验科学,所以需要调试和分析。

优化性能的领域:小型嵌入式设备和移动设备、大型服务器、分布式计算等计算资源有限的场合。

(1)C++ 代码优化策略总结:

1. 用好的编译器并与好编译器

(1)使用支持C++11的编译器,-std-c++11,
(2)打开编译器的优化选项,-O2,但是代码调试过程会变的困难
(3)打开函数内联优化选项,inline
(4)编译器编译出的程序性能:INTEL icc > GNU gcc

2. 使用更好的算法

大部分优化手段可将程序性能提升30%-100%或3倍,但使用更高效的算法,可以实现性能的指数级增长。
(1)使用 查找 和 排序 的最优算法
(2)具体领域的最优算法
(3)技巧:预计算(将计算从运行时移动到链接、编译或是设计时)、延迟计算(将计算推迟到真正需要使用该计算结果时,才进行计算)、缓存(节省和复用,减少数据无用的换入换出,也就是减少了L1/L2/L3的带宽)

3. 使用更好的库

标准C++模板库和运行时库必须是可维护的、全面的、非常健壮的,所以性能

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C++性能优化 指南(强列推荐) chm版 Part I: Everything But the Code Chapter 1. Optimizing: What Is It All About? Performance Footprint Summary Chapter 2. Creating a New System System Requirements System Design Issues The Development Process Data Processing Methods Summary Chapter 3. Modifying an Existing System Identifying What to Modify Beginning Your Optimization Analyzing Target Areas Performing the Optimizations Summary Part II: Getting Our Hands Dirty Chapter 4. Tools and Languages Tools You Cannot Do Without Optimizing with Help from the Compiler The Language for the Job Summary Chapter 5. Measuring Time and Complexity The Marriage of Theory and Practice System Influences Summary Chapter 6. The Standard C/C++ Variables Variable Base Types Grouping Base Types Summary Chapter 7. Basic Programming Statements Selectors Loops Summary Chapter 8. Functions Invoking Functions Passing Data to Functions Early Returns Functions as Class Methods Summary Chapter 9. Efficient Memory Management Memory Fragmentation Memory Management Resizable Data Structures Summary Chapter 10. Blocks of Data Comparing Blocks of Data The Theory of Sorting Data Sorting Techniques Summary Chapter 11. Storage Structures Arrays Linked Lists Hash Tables Binary Trees Red/Black Trees Summary Chapter 12. Optimizing IO Efficient Screen Output Efficient Binary File IO Efficient Text File IO Summary Chapter 13. Optimizing Your Code Further Arithmetic Operations Operating System–Based Optimizations Summary Part III: Tips and Pitfalls Chapter 14. Tips Tricks Preparing for the Future Chapter 15. Pitfalls Algorithmic Pitfalls Typos that Compile Other Pitfalls
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值