program/code optimization

In computer scienceprogram optimization or software optimization is the process of modifying a software system to make some aspect of it work moreefficiently or use fewer resources.In general, a computer program may be optimized so that it executes more rapidly, or is capable of operating with lessmemory storage or other resources, or draw less power. (wiki)

Levels of optimization

Design - architecture(network latency bounded, program language, platform, goal)
Algorithm and data structure - algorithm(constant,logarithmic,linear,log-linear; quadratic complexity O(n^2) fail to scale); data structure(use abstract data types in function definitions, restrict the concrete definition to a few places); memoization (cache the result of expensize function call)
source code level - for, while
build level - optimizing compile; preprocessor directive(for specific hardware)
assembly language - operating system on embedded systems writen in assembly language

Algorithm and data structure 

algorithm(constant,logarithmic,linear,log-linear; quadratic complexity O(n^2) fail to scale); 
data structure(use abstract data types in function definitions, restrict the concrete definition to a few places)
memoization (cache the result of expensize function call)

optimize the code

limitation of the compiler

1. alias of the storage address - two pointer points to the same address
2. side effect of subfunction - subfunction change the value of global variable

loop-invariant code motion - low efficiency of the for loop

as to some code in the for loop, the execution result remains the same with every iteration. it would be more efficient to move this code block out of the for loop

reduce unnecessary reference/read/access to the memory/storage/disk

if it is not the final value, it is better to store it to a temporary varaible. And, just write the final result once to the memory. This reduce the memory access.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值