The following uses an example to briefly describe the timing method of the C ++ program.
# Include <iostream>
# Include <ctime>
Using namespace STD;
Void main ()
{
Clock_t start, finish;
Start = clock ();
Int one;
Int & Rone = one;
One = 5;
Cout <"One:" <one <Endl;
Cout <"Rone:" <Rone <Endl;
Cout <"& one:" <& one <Endl;
Cout <"& Rone:" <& Rone <Endl;
Int two = 28;
Rone = two;
Cout <"One:" <one <Endl;
Cout <"two:" <two <Endl;
Cout <"Rone:" <Rone <Endl;
Cout <"& one:" <& one <Endl;
Cout <"& two:" <& Two <Endl;
Cout <"& Rone:" <& Rone <Endl;
Finish = clock ();
Cout <"time spent" <(finish-Start)/clocks_per_sec <"S" <Endl;
}
§ Program timing requires you to know the time when the program starts computing and ends computing. c ++ program timing can directly reference the CPU pulse-Pulse Count Special Data Type: clock_t-Number of pulses per second: clocks_per_sec is actually a macro # define clocks_per_sec 1000-header file: <ctime>
Define the Pulse Count variable:
-
Start = clock ();{...} Finish = clock (); cout <"The operation time consumed is:" <double (finish-Start)/clocks_per_sec
Clock_t start, finish;