OO IN C (3): Performance Analysis of Class Simulation

xiaoxiao2021-03-06  62

Class simulation performance analysis

A large number of function pointers, structures, and the like are used in class simulation, and there must be performance analysis to observe what is the extent of the overall performance of the program.

1. Function call overhead

#define counter xx

void testfunc ()

{

INT I, K = 0;

For (i = 0; i

}

In the test program, we use a test function, and the inside of the function body can change the time consumption of the function by changing the value of YY. The test contrast is the cycle calls the XX times function, and the YY cycle inside the loop XX function.

It was found that when YY is small enough, the function calls time consumption becomes the main reason. So when a "simple" function needs "repeated" call, write it as a function will have an impact on performance. This time you can use macros, or inline keywords.

However, when I set up XX = 10000000 (10 million), only the MS level time consumption, for non-real-time operation (UI, etc.), even very slow CPU (embedded 10M level), It is only a short function call consumption when XX = 100,000, so this is actually ignored.

2. Ordinary function call and function pointer call

Void (* tf) ();

TF = TestFunc;

The test program is modified to a function call, a function pointer call. Test found that there is no impact on time. (When you write, it is found that the function call is time consumption (XX = 100 million), the function pointer is slow (Release version), the call consumes 350: 500. Later, this impact is found. Since the variable is applied for a global reason, the accesses of global variables are much slower than the local variables).

3. Overhead of function pointers and pointer structures

Struct a {

Void (* tf) ();

}

The test program is modified to use the structure of the function pointer, and the test finds that there is no impact on time. In fact, the use structure does not have an impact because the structure of the structure is fixed offset. Therefore, the access of structural variables and the access of ordinary variables are the same for the machine code.

Test Conclusion: The use of class simulation will not have much impact on performance.

转载请注明原文地址:https://www.9cbs.com/read-112460.html

New Post(0)