Three test time methods for code in codeblocks

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.