Can anyone tell me what is the best way to know the execution time of my source code? Best means that the execution of that method to determine time doesn't affect or has minimal effect on the code's actual runtime.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
8 | Dominater069 | 154 |
8 | nor | 154 |
Can anyone tell me what is the best way to know the execution time of my source code? Best means that the execution of that method to determine time doesn't affect or has minimal effect on the code's actual runtime.
Name |
---|
At the end of your source code you can do something like:
I also use this and bdw you don't need to use that #ifdef because the cerr writes to the stderr , not the stdout and codeforces or any other site won't show WA because of cerr statements
I don't do it because:
Theoretically, it'll increase run time :P
I think it is a bad programming practice to use
cerr
in that way. Similarly for usingcerr
for debugging the program in that way. I instead like how the top guys do, they have debug template and useifdef
to print the debug output only locally.This
std::chrono::system_clock::now().time_since_epoch().count()
returns current time in nanosecond.Or you can use custom invocations.
Use ideone.com. Make sure that your code is private during contest.
During compiling use this time g++ -std=c++17 cprog.cpp
Then after execution last line will show:
g++ -std=c++17 cprog.cpp 1.31s user 0.10s system 99% cpu 1.415 total
I personally like this over writing some code
You can have it prewritten so that you don't have to write it again and again in the terminal. Endagorion does the same too.