The timing function in C/s + + is clock (), and its associated data type is clock_t.
In MSDN, the clock function is identified as follows: clock_t clock (void); This function returns the number of CPU clock timing units (clock tick) between the time the "start this program process" and the call to clock () function in the program), which is called the Wall Clock Time (Wal-clock) in MSDN. Where clock_t is the data type used to hold the time, in the Time.h file,
We can find the definition of it:
#ifndef _clock_t_defined
typedef long CLOCK_T;
#define _clock_t_defined
#endif
Obviously, clock_t is a long shaping number. In the time.h file, a constant clocks_per_sec is also defined to indicate how many clock ticks will be in a second, defined as follows:
#define CLOCKS_PER_SEC ((clock_t) 1000) can see every 1 per thousand seconds (1 milliseconds), and the value returned by the clock () function is added 1.
Copy Code code as follows:
#include <iostream>
#include <ctime>
using namespace Std
Int main ()
{
long n=0;
clock_t start,finish;
Start=clock ();
while (n<1000000000)
n++;
Finish=clock ();
cout<< (finish-start)/clocks_per_sec<<endl;
return 0;
}