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 | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
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.