当前位置:网站首页>C and pointer Chapter 18 runtime efficiency 18.3 runtime efficiency
C and pointer Chapter 18 runtime efficiency 18.3 runtime efficiency
2022-07-27 00:15:00 【weixin_ Guest time】
18.3 Runtime efficiency
When the capacity of the program after growth exceeds the amount of memory , It won't work , This belongs to “ Too big ”. Even on some modern machines , One must be stored in ROM The program must be quite small , It is possible to load into the limited memory space .
But many modern computer systems are far less restrictive in this regard , This is because virtual memory is provided (virtual memory). Virtual memory is implemented by the operating system , It needs to put the active part of the program into memory and copy the inactive part to disk , This allows the system to run large programs . But the bigger the program , The more replication is required . So large programs are not as impossible to run as before , But as the program grows , Execution efficiency gradually decreases . therefore , When does it appear “ Too big ” Well ? When it runs too slowly .
The execution speed of a program is obviously related to its volume . The slower the program executes , The more uncomfortable it will be to use this program . It is difficult for us to define at what point a program is suddenly detained “ Too slow ” The hat of . Unless it has to respond to some physical events beyond its control . for example , One operation CD If the player's program can't process the data as fast as the data from CD The speed of transmission , It's obviously too slow .
Increase of efficiency
Modern code is optimized from a C The program is very good at generating efficient object code . therefore , Spend time making small changes to the code to make it more efficient , It's often not very cost-effective .
Tips :
If a program is too big or too slow , Instead of delving into each variable , Look at declaring them register Can we improve efficiency , It is far better to choose a more efficient algorithm or data structure , This effect is more satisfactory . then , This is not to say that you can misbehave in your code , Because bad code always makes things worse . If a program is too big , It's easy to think of where to start and make the program smaller : The largest function and data structure . But if a program is too slow , Where should we start to improve its speed ? The answer is to evaluate the performance of the program , Simply put, it is to measure the time spent in the execution of each part of the program . The part that takes the most time is obviously the goal of optimization . The most frequently used part of the program , If you can run faster , It will greatly improve the overall running speed of the program .
You can find from this list 3 An interesting place .
1. Among the most time-consuming functions , Some are library functions . In this case ,malloc and free Take the top two . We cannot modify their implementation , But when redesigning the program , If there is no or less dynamic memory allocation , The execution speed of the program can be improved at most 25%.
2. Some functions take a lot of time , Because they are called many times . It's fast when called individually several times , But due to frequent calls , Therefore, there is a lot of time . Add a few wise register Declaring slightly improves the efficiency of the function , The overall performance of the program may be greatly improved .
3. Some functions are not called many times , But each call takes a long time . Finding a faster algorithm for this function can at most improve the speed of the program .
As a last resort , We can recode a single function with assembly statements , Smaller function , The easier it is to recode . This method may work well , Because in small functions ,C The fixed cost of function order and function postscript of takes a large proportion in the execution time . Recoding larger functions is much more difficult , Therefore, it is not very efficient to spend time in this place .
Performance evaluation often doesn't tell you what you didn't know , But sometimes its results can be quite unexpected . The advantage of performance evaluation is that you will find out which part of the program you are spending time studying , It may bring maximum performance improvement .
边栏推荐
- Pytorch data pipeline standardized code template
- Practice of data storage scheme in distributed system
- 4-4 object lifecycle
- Mysql database complex operations: Database Constraints, query / connect table operations
- Section 6: introduction to cmake grammar
- AlexNet(Pytorch实现)
- Relationship between Unicode and UTF-8
- [Gorm] model relationship -hasone
- 13_ conditional rendering
- Codeforces B. Orac and Models (dp)
猜你喜欢

At 12:00 on July 17, 2022, the departure of love life on June 28 was basically completed, and it needs to rebound

【C语言】数组

Meeting OA my meeting

Pytorch学习记录(二):张量

Chapter 7 course summary

Midge paper reading notes

卷积神经网络——LeNet(pytorch实现)

In depth interpretation of the investment logic of the consortium's participation in the privatization of Twitter

04-传统的Synchronized锁

Everything you should know about wearable NFT!
随机推荐
Training team lpoj round10 d come minion!
第7章 课程总结
In depth interpretation of the investment logic of the consortium's participation in the privatization of Twitter
【C语言】数组
Training team lpoj round10 e Jumping Frog
第6节:cmake语法介绍
The difference between SQL join and related subinquiry
第3章 跨域问题
Abstract classes and interfaces (sorting out some knowledge points)
Share a regular expression
Codeforces E. maximum subsequence value (greed + pigeon nest principle)
Baidu website Collection
The attorney general and the director of the national security service of Ukraine were dismissed
DHCP, VLAN, NAT, large comprehensive experiment
告别宽表,用 DQL 成就新一代 BI
Add an article ----- scanf usage
Number that cannot be bought
Midge paper reading notes
[C language] array
uni-app学习(二)