In our actual programming work, we often need to measure the running time of the program, such as the running time of the algorithm. Here I collected methods for online centralized measurement of program running time.
Check the information on the Internet and find the following methods for obtaining the program running time in VC:
Method 1 using the gettickcount function (MS)
Code:
Cstring
STR;
Longt1 = gettickcount (); // gets the system running time (MS) before the start of the program segment)
...... // To do something
Longt2 = gettickcount (); // gets the system Runtime (MS) after the program segment ends)
Str. Format ("Time: % DMS", t2-t1); // The difference between front and back is the running time
Afxmessagebox (STR );
Method 2 use the C/C ++ timing function (s)
Code:
# Include "time. H"
Clock_t Start, Finish;
Start= Clock ();
Finish
=
Clock ();
Printf ("% F seconds \ n", (double) (finish-Start)/clocks_per_sec );
Method 3Use the ctime class to obtain the system time
Code:
Cstring STR;
// Obtain the system time
Ctime TM;
TM = ctime: getcurrenttime ();
STR = TM. Format ("the current time is % Y, % m, % d.% X");
Afxmessagebox (STR );
Method 4Use the getlocaltime class to obtain the system time
Systemtime st;
Cstring strdate, strtime;
Getlocaltime (& St );
Strdate. Format ("m ----", st. wyear, st. wmonth, st. wday );
Strtime. Format ("-:-", st. whour, st. wminute, st. wsecond );
Afxmessagebox (strdate );
Afxmessagebox (strtime );
Method 5 Use API functions
BOOL QueryPerformanceCounter( LARGE_INTEGER *lpPerformanceCount // counter value);
I have found these methods. If you have any new methods, share them with you.