9条c程序性能优化指南

1.循环的判断语句约占用了执行时间的17%。


2.编译器会对程序进行一定程度的优化,如:

(1) a += b1; a += b2; …… a += bn;

     编译器会合并为

     a += n*b;

(2) a = 3; a = 3;……a = 3;

     编译器会去除无作用的单一重复语句。


3.常量赋值、运算比变量快。


4.不存在依赖关系的语句,CPU可并行处理,如:

   依赖关系:a += b; c += a;

   无依赖关系:a += b; c += b;

   Tips: 尽量避免等待前一操作的执行结果。

            在统计数值时,避免单个变量进行统计,应分成若干个变量进行统计后合并。


5.运算对象的变量越多,处理时间反而越短,因为CPU可以并行处理,当变量个数与CPU运算器个数相同时最快。


6.乘法运算时间是加法的3倍:0.9 : 0.3(纳秒),除法运算最慢:7.3纳秒。


7.无符号除法运算(unsigned)比带符号的要快得多。


8.if...else... 条件成立比不成立的执行时间短。


9.32位环境下函数调用:无参数比有参数快10%;64位环境由于有较多寄存器,时间差别不大。



  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值