A summary and some questions about code running efficiency

Source: Internet
Author: User
First, you must admit that this casual name is a bit awkward.
Since the development of gea52, I have been thinking about Program Efficiency issues. According to your previous ideas, the program runs slowly. There may be many situations, and performance bottlenecks may occur on the memory of the Web server and the CPU of the Web server, i/O overhead between the Web server and the DB server. In short, it is difficult to solve the performance problem without careful analysis and hard debugging. Sometimes, when some operations really consume system resources, You have to manually limit the number of concurrent tasks and change the number of concurrent tasks and perform serial operations to ensure the running efficiency of other operations. However, after debugging this morning, my views have changed a little bit.
In an existing web system, I reconstructed a module. This refactoring is not intended to improve Code Structure or improve code efficiency, only used to change the module Algorithm . The efficiency of the new algorithm is similar to that of the old algorithm. However, after reconstruction, I found that the system performance has been greatly reduced, and the time consumption for processing the same amount of data has increased by 1000 times! At the beginning, I was very frustrated. I checked the execution process of the main parts involved in the refactoring and found no doubts. The memory occupied by the system is the same as before. The number of execution times of the loop body is the same as before. The IO between the system and the database is only one time and very fast. What is the problem? Finally, I used the dumbest method to comment out statements that I think may be a bottleneck in the running speed, and then gradually narrow down the scope of doubt. Finally, I found this bug on the fourth layer of the loop, which is an unnecessary call to a very heavy method. You know, in the layer-3 Loop, less than 5% of the loops will enter the layer-4 loop where a bug occurs, so I never doubted it at the beginning. But in the end, this unfortunate 5% took 99.9% of the system's running time.
The truth is actually quite simple. I'm afraid we learned it when we first got into the sophomore year, that is, do not put too time-consuming statements in the loop body. It is a pity that when I have more things, I forget the most basic principle. I am not careful when writing code. I seldom consider the execution efficiency of the method calls in the loop body.

Put this item in the question area. Is there a lightweight dynamic testing tool under. Net that can analyze the execution bottleneck of a given code block? (For example, the execution time percentage of each statement is given .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.