1. Entariance is expensive. I didn't think of it, and if the surplus operator will become an optimized object, an example of writing a loop linked list: INT A [n]; void append (int m) {i = i 1)% n; a [i] = m;}
See, how much simple code, how wonderful, you can't see anything, however, when you say that you want to optimize it, you will not fall? At least I am like this. "Although most The arithmetic operation takes approximately 10 nanosecond times, but% is close to 100 nanoseconds,% overhead is and its expensive! "The optimized suggestion is to let you use inexpensive logic to replace% operation: i; IF (i == n) i = 0; a [i] = m; this way this code is the core of your program, it is estimated that he can make your program twice a time. 2. Optimization of loops. this I am also surprised by it. It is not how mysterious him. It is actually very good, but due to the influence of directional thinking, we have never considered the problem can be optimized: First, you can judge the condition of the loop. For example Find a value in an array, find B in A [N], very clear order we write the most code: Search (int A [】, int b) {for (int i = 0; i
For this problem, we know that the value of i is certain, because the power of 2 is certain, the range can be taken is {512, 256, 128, 64, 32, 16, 8, 4, 2, 1}, therefore Reasons do not use cycles, even if the amount of code increases, the performance has improved a lot, why not? See: p = -1; if (a [p 512] 1000 || A [q]! = B) q = -1; return q; first is 1000-512 is because the length of the following may be no 256, so that you will not know how much you know this. Wonderful, I can handle the size of the scale of 2000, add a statement, and you can handle the statement of 4000, you can only use it just some simple judgments, it has been It is impeccable if you have a very complex matrix problem, I hope that you can do this, is of course the efficiency is a key factor to see your project, the company is decided, but I have reason to believe you. I can have the same feelings as I have the same feelings, God can give us such wonderful things.
Cao Xihua .2004 / 11/17
Note: