Software architecture ———— Code adjustment Strategy and technology

Source: Internet
Author: User

Performance

For users, programmers are delivering software, providing a refreshing user interface, and avoiding system crashes is often more important than the performance of the program.

There is a loose relationship between performance and code speed. This kind of work is a bit forgotten how if you're just focusing on how fast your code is running. In particular, be careful about giving up other functional areas to make your code run faster. If the speed is too much emphasis, the overall performance of the program often does not rise against the drop.


Performance and Code tuning

Program requirements: Before you spend time dealing with performance issues, think about whether you are solving a problem that really needs to be addressed.

Program Design: Program design includes the main framework of a single program, mainly including how the program is decomposed into classes. Sometimes the design of a program makes it difficult to implement a high-performance system. Some of the other designs are a breeze. Prioritize overall performance when designing the framework, and then set the resource footprint targets to be met for individual subsystems, features, and classes.

Classes and sub-programming: The internal mechanisms for designing classes and subroutines provide another opportunity for high-performance design. In this level of processing, the choice of the appropriate data types and algorithms will have a significant impact on performance.

Interaction with the operating system: it may not be noticed that the program is interacting with the operating system, because sometimes the compiler generates system calls or the library uses unexpected system calls.

Code compilation: A good compiler translates clear, high-level languages into optimized machine codes.

Hardware: Sometimes the most economical and effective way to improve program performance is to buy new hardware devices.

Code tuning: A practice of tweaking the correct code to make the code run more efficiently.


About Code adjustments

The problem with code sizing is that efficient code is not necessarily "better" code.


Some nonsense

1, in the high-level language, reduce the number of lines of code can increase the speed of the generated machine code, or reduce the use of its resources-error: The beauty of the code aside, the number of high-level language code and the final program of resource consumption and speed is not necessarily linked.

2, the specific operation may be faster than the other, the code size is also small-error: When discussing the performance of the program, there is no "possible" position of the word. You should actually measure the performance of your program so that you know whether the change is improving or reducing program performance. When the code is adjusted, it should be re-tested and adjusted according to the changes in the environment.

3, should be optimized at any time-error: A theory that if you make every kid program to achieve the fastest and smallest, then the program will be very small and run fast. Such a method would be very busy with the optimization of the micro-range, thus ignoring the important optimization of the overall system.

4, the running speed of the program is as important as its correctness-error: For a particular type of project, the speed of running or resource consumption is a key issue that programmers need to consider. This type of project is less than people usually think, and it will become less and fewer over time. The performance risks of such projects must be circumvented by initial design. For other projects, premature optimization can pose a serious threat to the overall performance quality of the software, and may even include software performance.


When to adjust the code

Programmers should use a high-quality design to write the program correctly. The modularity of the design is easy to modify, which makes it easy for later maintenance work to be made. Once the program is properly completed, check the performance of the system. If the program is running slow, try to make it faster and smaller. Unless you are clear about what you need to do, never optimize your program.


Common low-efficiency sources

1. Input/output operation, one of the root causes of inefficiencies in common programs is unnecessary input and output. If you can choose to work with your files in memory, do not try to access the same files through disk, database, or across the network. Unless the program is sensitive to space usage, the data should be processed in memory.

2, paging problem, the operation of the operating system to swap memory pages is much slower than in memory on the same page of the operation.

3, the system call, if the performance of the program has become a problem, then you should find out how the system calls to pay you how much cost.

4, interpreted language, interpretation of the language seems to be the system can be found in the damage to explain, before the machine code creation and execution, the interpretation of the language must process each program instruction.

5, error, the final problem of program performance is the error in the code. These errors may be not debugging code, forgetting to free up memory, database table design errors, polling for devices that are not saved, or even timeouts, and so on.


Performance measurement

Experience is not much help for performance optimization. A person's experience may come from an old computer, perhaps from an outdated language or compiler--and after any change in any one of these factors, all the experiences will become bullshit. The impact of an optimization can never be determined unless the effect is measured and evaluated. If there is no measurement of performance changes, then the result of the assumption of optimization is just the code becomes more obscure.


Performance measurements should be accurate

Should be assigned to the program CPU clock to calculate, not the date clock. Otherwise, when the system switches from its own program to other programs, the time counted on a program header is actually occupied by other programs.



Software architecture ———— Code adjustment Strategy and technology

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.