How to know the execution time of my program ?
- Execution time is displayed just below green tick(AC) which you see when your code is correct.
- You can click on desired solved problem displayed on your account page, now that will display whole chart of your submissions for that particular problem.
i am using dev c++,so can’t it be calculated there??
Try codeblocks. However you may use clock() function in <time.h> to calculate time elapsed in executing a block of code.
Useful Links :
You can insert this code snippet before input.
#ifndef ONLINE_JUDGE time_t start = clock(); #endif
and then you can write this at the end of printing output
#ifndef ONLINE_JUDGE time_t end = clock(); printf("Time: %.2lf sec\n", (end-start)/double(CLOCKS_PER_SEC)); #endif
Then you should run the program with redirecting an input test file (assuming that you have created it beforehand), and then you can observe the output at the screen itself OR you can redirect output to some file if the number of test cases is huge!
wonder@ubuntu:~$ gcc -o sample sample.c wonder@ubuntu:~$ ./sample < testinput.in > testoutput.out
Or you can also use the C function
freopen() in the corresponding mode (r or w) for the corresponding task. Example:
#ifndef ONLINE_JUDGE freopen("abc.in","r",stdin); #endif
Note: You must have to include the header
ctime in C++ (
time.h in C) for using the