当前位置:网站首页>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 .
边栏推荐
- Xi IO flow
- Pytoch monolayer bidirectional_ LSTM implements MNIST and fashionmnist data classification
- One article tells the latest and complete learning materials of flutter
- MySQL basic operation -dql
- 【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
- Clear neo4j database data
- Seven polymorphisms
- IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
- Array cyclic shift problem
- ZABBIX customized monitoring disk IO performance
猜你喜欢
Redis clean cache
Matlab imoverlay function (burn binary mask into two-dimensional image)
Intern position selection and simplified career development planning in Internet companies
Matlab label2idx function (convert the label matrix into a cell array with linear index)
ZABBIX customized monitoring disk IO performance
Pytorch two-layer loop to realize the segmentation of large pictures
Ecplise development environment configuration and simple web project construction
Get data from the database when using JMeter for database assertion
Automated test lifecycle
Mmclassification training custom data
随机推荐
MySQL regular expression
The relationship between the size change of characteristic graph and various parameters before and after DL convolution operation
The evolution of mobile cross platform technology
Deep discussion on the decoding of sent protocol
什么是数字化存在?数字化转型要先从数字化存在开始
A new WiFi option for smart home -- the application of simplewifi in wireless smart home
ABAP table lookup program
Image hyperspectral experiment: srcnn/fsrcnn
A guide to threaded and asynchronous UI development in the "quick start fluent Development Series tutorials"
Hexadecimal conversion summary
Summary of C language learning problems (VS)
How does MySQL execute an SQL statement?
PXE启动配置及原理
How to design an interface?
Codeforces Round #804 (Div. 2)
MySQL view
byte2String、string2Byte
How to clear floating?
Understanding the architecture type of mobile CPU
Pytoch uses torchnet Classerrormeter in meter