C language is inseparable from functions, and it is convenient to use functions, but it is costly to use functions;
In particular, during repeated calls, the function will waste some time due to repeated pressure stacks and outbound stacks.
The following is a test. The time for using a function is 8 seconds and 4 seconds, respectively!
1. Test the cost of using the function:
# Include <stdio. h> # include <time. h> int sum (int x) {return x + X;} int main (void) {int COUNT = 1000000000; int I; int num; time_t start, stop; time (& START); for (I = 0; I
2. Use inline functions:
The Inline keyword on the function header is the inline function.
Using inline functions can optimize the functions. The so-called optimization is to embed the functions into the current position.
Generally, you can only consider using inline for small functions, because this is only an application, and the compiler does not guarantee to execute Inline for all applications.
Inline functions can only use units defined (rather than declared.
The above example (only one inline is added) is used for testing.
After several tests, the test results are basically the same as the above. It seems that C ++ builder 2009 does not care about it.
# Include <stdio. h> inline int sum (int x) {return x + X;} int main (void) {int COUNT = 1000000000; int I; int num; time_t start, stop; time (& START); for (I = 0; I