当前位置:网站首页>Programming skills for optimizing program performance
Programming skills for optimizing program performance
2022-07-05 12:28:00 【yang881221】
After reading 《 Deep understanding of computer systems 》, Our programming is not just simple code . Instead, we should combine the foundation of the system to write more optimized code . We write code by understanding how computers work . Look at our code at a lower level , Perhaps a simple loop can change the overall efficiency of the code .
Modern compilers are complex , It does a lot of work for the program , The goal is to make the program safer and faster . For example, our compilation optimization options -Og -O1 -O2 -O3 etc. , But also due to optimization , Our machine instructions are arranged “ Beyond recognition ”, If you don't believe it, you can use the optimized code to disassemble , It will be much more than you think .
Here are a few guidelines that apply
1. Eliminate the inefficiency of the cycle , Never add extra calculations , What should be moved outside the circulation is moved outside the circulation
2. Reduce procedure calls , Of course, this is a double-edged sword , For example, the use of inline functions , But if you reduce it too much , It will make our code logic messy
3. Reduce unnecessary memory references , The best examples here are copy constructors and move constructors . After all, deposit access and cpu Compared with the execution cycle of , Too slow .
4. Try to improve cache shooting , This requires writing code , Try to put frequently accessed data into one cacheline in , Or do cacheline Alignment of , Here is another double-edged sword , It may waste a lot of space after alignment , After all cache Still valuable .
5. Loop unrolling , Use circular blocking , Reduce the number of iterations of the loop , Increase the number of elements calculated per iteration . Reduces the number of operations that do not directly contribute to program results , Provide some ways to optimize your code , Reduce the number of operations on the critical path in the whole calculation .
6. Improve parallelism , Contemporary computer systems are basically multi-core architecture , Different cores can process different data , Of course, the splitting of data here is very important , In particular, the correlation of data has a great impact on parallelism .
7. Write code suitable for conditional delivery , After all, branch prediction is miss The price is relatively high , Need to fill in the assembly line again .
8. Understand memory performance , Memory bus bandwidth , If you can use register variables, you don't need memory variables .
9. By using multiple accumulation variables and recombination techniques , Find ways to improve the parallelism of instruction sets .
10. Try to reduce cache line Of miss and cache The shaking of .
11. Disassemble the code of high-level language , Find ways to optimize from the assembly .
边栏推荐
- Complete activity switching according to sliding
- Cypher syntax of neo4j graph database
- Acid transaction theory
- Pytorch two-layer loop to realize the segmentation of large pictures
- Hexadecimal conversion summary
- Tabbar configuration at the bottom of wechat applet
- 手机 CPU 架构类型了解
- Pytoch uses torchnet Classerrormeter in meter
- MySQL splits strings for conditional queries
- 16 channel water lamp experiment based on Proteus (assembly language)
猜你喜欢
嵌入式软件架构设计-消息交互
Get the variable address of structure member in C language
Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
The evolution of mobile cross platform technology
Detailed structure and code of inception V3
Embedded software architecture design - message interaction
July Huaqing learning-1
The survey shows that traditional data security tools cannot resist blackmail software attacks in 60% of cases
ZABBIX ODBC database monitoring
Tabbar configuration at the bottom of wechat applet
随机推荐
Is investment and finance suitable for girls? What financial products can girls buy?
[hdu 2096] Xiaoming a+b
Pytoch through datasets Imagefolder loads datasets directly from files
Video networkState 属性
Yum only downloads the RPM package of the software to the specified directory without installing it
信息服务器怎么恢复,服务器数据恢复怎么弄[通俗易懂]
Hexadecimal conversion summary
Deep discussion on the decoding of sent protocol
Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
Error modulenotfounderror: no module named 'cv2 aruco‘
mysql拆分字符串做条件查询
C language structure is initialized as a function parameter
Xi IO flow
MVVM framework part I lifecycle
强化学习-学习笔记3 | 策略学习
MySQL splits strings for conditional queries
Learning JVM garbage collection 06 - memory set and card table (hotspot)
Detailed steps for upgrading window mysql5.5 to 5.7.36
How to recover the information server and how to recover the server data [easy to understand]
Resnet18 actual battle Baoke dream spirit