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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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.