Execution time of the calculation program

xiaoxiao2021-03-06  54

鼓 集 行 集

Sometimes, we need to quantify the execution time of a program, which can be done with the C function clock.

The prototype of the clock function is

Clock_t clock (void);

Its return value is the time using the CPU with the current process of Clock Tick. Returns -1 when this time cannot be obtained. A Clock Tick is a time unit that defines several clock ticks in a second. In VC , this number is defined as Clocks_Per_Sec. So Clock Tick / Clock_Per_Sec can derive the execution time in seconds.

The following code is a typical example of using a clock to calculate a program execution time.

Clock_t start, finish;

Double duration;

START = clock ();

// TODO requires measurement blocks

Finish = clock ();

DURATION = (Double) / clocks_per_sec;

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

New Post(0)