The summary in this article is my personal opinion and remains to be discussed. I hope you will discuss it more.
1. A ++ and ++
Use ++ a whenever possible, because in general, ++ A is faster than a ++.
Why? Because the implementation of ++ A is to first add the aplus 1 (INC command), and then transfer the address of a; and the implementation of a ++, also, copy a to memory unit B first, then a + 1 (INC command), and then transfer the address of B. Therefore, if a ++ is compared with ++ a, a duplicate copy will reduce the speed.
2. Const modification is faster than non-const modification.
Obviously, when the compiler is optimizing, the const object is not modified, but can be put forward and reused. Therefore, the optimization rate is obviously higher than that of non-const, and the speed will be correspondingly improved.
3. Try to use the switch as much as possible, because the switch is not a simple if-Else, and the switch speed is close to goto!
Because the switch is to generate all the code in the same region, and then hash the code to a running position based on different cases. Therefore, it is constantly compared with if-Else, the speed is obviously greatly improved. This also explains why the switch can only use the int type, because the hash of other types is not obvious, which is also the reason for break, because there is no break, the code will be continuously executed in the program segment produced by the switch, and will jump out only when break is encountered.
All of the above are discovered by myself implementing the compiler or reading some compilation books, which need to be discussed, but basically I have done experiments and should be consistent