Let us pay attention to program operation efficiency
At first, the program running efficiency has always been the topic of people who study computers. However, with the rapid development of hardware, the concept of "running efficiency" is already in the campus and beginners, and it can only be seen when designing business software development and programming competition. This is our current situation and it is also worth thinking about.
Is it necessary to improve the running efficiency of the program?
With the development of computer hardware, the speed of the microcomputer is getting faster and faster (the frequency of the Pentium 4 processor has been applied 3G, synchronous cache has been applied), and the ability to run software is getting stronger and stronger, and it seems that the operation of the program. Efficiency is not the focus of our attention. Indeed, in the classroom classroom, the teacher hardly talked this, and the classmates are also known for this; many programming books are not asking. Is it really not important? In fact, efficiency is very important, otherwise there is no work efficiency. Beginners believe that it is not important, that is because it can't write more efficient procedures; even if it can be written, it will not feel the difference in execution because the program is too small. In some embedded systems, the operational efficiency of the program is particularly important; the efficiency of the small segment code directly affects the running speed of large software. So, we must improve your own procedure and make it faster and better.
Is the daily speed algorithm are fully effective?
People's daily speed algorithms are not fully effective for computers. For example: Everyone knows how to calculate from 1 to 100: can be 1 2 3 .... 100 calculate 5050; or use a simple algorithm: (0 100) (1 99) (2 98) ... resulting results also 5050. Obviously, the second method is more suitable for people, and its efficiency is much higher than the order, and even the spending will quickly get answers. However, for a computer, the second method is not fast than the first, and if the program is not properly prepared, it will reduce the calculation speed. So I suggest you, for a general numerical calculation, you don't have to consider any speed algorithm, please believe in the CPU Central Affirmation.
Program algorithm is key
(1) Select the appropriate algorithm
To improve program operation efficiency, improve the algorithm is the most critical. The algorithm is the main factor affecting the efficiency of the program, and the appropriate algorithm is selected when writing different programs. For example, the same is a lookup algorithm. When processing different data, efficiency is different, this is to choose one of the best. Of still, in the same problem, you can use the stack or use the queue. At this time, it is necessary to consider which one is better, and consider the sequential structure or a chain structure. In summary, selecting the appropriate algorithm is the key to improving operational efficiency.
(2) Good at improved algorithm
Everyone must have learned the "bubble sort" algorithm and will be used. I don't know how many people have improved this "old" algorithm. In fact, the idea is very simple, and a flag is used to indicate the sequence that has already been acted. When you skip this paragraph, you can greatly improve the order efficiency. This is just a very simple example, the purpose is to encourage you to improve the existing algorithms, some good algorithms come out, which is necessary because the statement provided by the system is not used. Just check the database, the simplest is to use the SELECT statement. In fact, this statement is necessary to improve, if you write directly in large databases: SELECT XXX from XXX While XXX, it is conceivable that it is a low efficiency. Therefore, we must be good at improving existing algorithms.
(3) An idea is an idea I have improved the efficiency of the program - multi-operate, less memory operation. Because the operation is done by the operator in the CPU, the operation is to be in memory, and even in the abstament. The two have a few quantities, and the execution rate is of course different (although it can't be seen, it is actually different). Therefore, in the programming process, it can be directly calculated directly, and do not move the data to remove.
(4) Small advice
To write an efficient algorithm, it must be understood to basic data structures. It must be skilled in the basic algorithm. Therefore, it is recommended that you must learn the data structure, improve the ability of the algorithm in the continuous practice, so your program can be better efficient. Here is also suggested to see the "programming platform" of each issue of "programmer", where the procedures are efficient.
The purpose of I wrote this article is not to explain what algorithm is high, what algorithmic programming is used. Instead, I will launch a top question that is cold-defined in the times, allowing us to pay attention to the operational efficiency and make programming in the end.