I,
In Windows, it takes time in milliseconds to obtain the data.
Accurate Time (calculated based on CPU frequency) in Windows) # Include <windows. h> # Include <iostream> (Obtain CPU frequency) Large_integer T1, T2, feq; Queryperformancefrequency (& feq); // The number of beats per second Queryperformancecounter (& T1); // Number of pre-test beats For (INT I = 0; I <10000; I ++ ); Queryperformancecounter (& T2); // Number of beats after test Double D = (double) t2.quadpart-(double) t1.quadpart)/(double) feq. quadpart); // time difference second STD: cout <D <STD: Endl; Accurate Time in Windows DWORD gettickcount (void ); SDK: The gettickcount function retrieves the number of milliseconds that have elapsed since Windows was started. Ctime T = ctime: getcurrenttime (); SDK: This method obtainsCtimeObject that represents the current time. II, |
I initially used the timegettime () function, which can only be accurate to ms. The usage is as follows:
# Include <mmsystem. h>
Dowd begin, end;
Begin = timegettime ();
// The program fragment you want to calculate
End = timegettime ();
Cstring strtime;
Strtime. Format ("% d", end-Start );
Finally, set linker-input-additional dependencies and winmm. Lib in your project.
If you want to display the subtle level, it is not enough. You can use the system counter.
Large_integer frequency;
Queryperformancefrequency (& frequency );
Large_integer start, end;
Queryperformancecounter (& START );
// The program fragment you want to calculate
Queryperformancecounter (& End );
Int time = (end. quadpart-start. quadpart) * 1000000)/frequency. quadpart );
Useful link: http://dev.csdn.net/develop/article/41/41104.shtm
Http://dev.csdn.net/article/74/74169.shtm