Class simulation uses a large number of function pointers, struct, and so on. Performance analysis is required to observe the effect of such a structure on program integrity.
1. function call overhead
# Define COUNTER XX
Void testfunc ()
{
Int I, k = 0;
For (I = 0; I <YY; I ++) {k ++ ;}
}
In the test program, we use a test function. In the function body, we can change the time consumption of the function by changing the YY value. The test comparison is to call the XX function cyclically and the YY cycle inside the XX function cyclically.
The result shows that function call time consumption is the main reason when YY is small enough and X is large enough. Therefore, when a "simple" function requires "repeated" calls, writing it as a function will affect the performance. In this case, you can use macros or the inline keyword.
However, when I set XX = 10000000 (10 million), the ms-level time consumption occurs. For non-real-time operations (UI, etc ), even a very slow cpu (embedded 10 m level) Only takes a short time to call a function when XX = 0.1 million. Therefore, this can be ignored.
2. overhead of common function calls and function pointer calls
Void (* tf )();
Tf = testfunc;
The test program is changed to a function call and a function pointer call. The test shows that there is basically no effect on the time. (During the first compilation, it was found that when function calling is time-consuming (XX = 0.1 billion), function pointer calling is slow (release version), and the call time is 350: 500. Later, we found that the reason for applying for a global variable is that the access to global variables is much slower than that of local variables ).
3. overhead of function pointer and pointer structure access
Struct {
Void (* tf )();
};
The test program changes to a function pointer using the structure, and the test finds that there is basically no impact on time. In fact, the use of the structure does not affect, because the structure access is fixed offset. Therefore, access to structure variables is the same as access to common variables for machine codes.
Test conclusion: the use of the class simulation method will not have a great impact on the performance.