Hey ...... In the past few days, the card time for the weekly competition is too tight, and the optimization constant of other teammates is too embarrassing. So I can only learn the method for testing the code. I found two methods online, then, the methods of teammates were added.
First:
# Include <time. h> int main () {clock_t starttime = clock (); {// here is the code to be tested;} clock_t endtime = clock (); cout <"Run Time:" <endtime-starttime <"Ms" <Endl ;}
Second:
# Include <windows. h> int main () {DWORD starttime = gettickcount (); {// here is the code to be tested;} DWORD endtime = gettickcount (); cout <"Run Time:" <endtime-starttime <"Ms" <Endl ;}
Third:
This powerful file testing method is suitable for testing file data.
In the installed codeblocks folder, there is an application named cb_console_runner, for example:
Copy it to the same path of your program. For example, my code program is on the desktop, and then I put this cb_console_runner on the desktop. Running, Operation: You first use codeblocksto run your program to a.exe application, then press and hold the shitf key on the desktop, then right-click, select: Open the command Window option here, and enter: cb_console_runner a.exe <1.txt> 2.txt. press the Enter key twice in a row. Then you can open 2.txt to check the running time of your program.
Cb_console_runner a.exe <1.txt> running.
Comparison of the three test times:
The first and second types are similar, because they are tested directly in the main function, so it may be faster than the third type. If you input data by hand in the running window, the program will run more time, because the first and second are the end time of the last program minus the start time, so it will be slow.
If all the data is read using files, the time for these three methods should be similar.
Three test time methods for code in codeblocks