Functionality Check

linux gcc 4.4.1 C99

I am wondering what is the best way to test C program performance.

I have some functions that I have implemented. However, I could use a different design for each function.

Basically, I need to check which design gives the best performance.

Many thanks,

+3
source share
6 answers

You can use gprof, which is a free profiler.

+1
source

Take a look at this post on code profilers.

+4
source

, .

? ! , , .

, " "? , :

  • 0,1 - , , , , , . ( 0,1 , 0,08, .. 80 .)

  • 1 - , , . , 0,1, 1,0 , , "" .

  • 10 - , . , , , . , .

, , . - , RAM, / , , , , , , . , ; . - ( ), , , - " , ?"


, , , valgrind (--tool=callgrind --dump-instr=yes) kcachegrind.

+3

. , , . Shark Mac OS X gprof Linux.

clock() getrusage(), , :

clock_t t = clock();
for (i = 0; i < 1000; ++i) my_func();
printf("time = %lf\n", (double)(clock() - t) / CLOCKS_PER_SEC);

Profiler , , . Calling clock()/getrusage() (), / .

+2

, , . , .

, , - , .

CPU wallclock-, .

+1

In addition to profiling, you need to run the test code from the harness (driver) to average the readings. Thus, your comparisons are not distorted by a single reading, so you have a large sample with average and standard deviation for comparison. There are many multi-threaded frameworks that can provide load loading.

0
source

Source: https://habr.com/ru/post/1726857/


All Articles