Calculating execution time in c++
Разница между en1 и en2, 548 символ(ов) изменены
Hi Codeforces. Today i saw [user:GreenGrape,2018-02-09] solution of the problem [D. Robot Vacuum Cleaner](http://codeforces.com/problemset/problem/922/D) : [solution](http://codeforces.com/contest/922/submission/ubmission:35053688)]. And i find there :↵

~~~~~↵
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)↵

while (t--) {↵
clock_t z = clock();↵
solve();↵
debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);↵
}↵
~~~~~↵

With this code he gets execution time of function `solve()`. `clock()` gives you current time. I
 have wrote helpful directivet is useful to avoid time limits. I have wrote helpful macro and decided to share with you :

~~~~~↵
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)↵
#ifndef time__              
#define time__(d
ata)for (long blockTime = =NULL; (blockTime == NULL ? ?(blockTime = =clock()) != NULL : :false); debug("%s : :%.4fs" ,data ,(double) (clock() - -blockTime) / /CLOCKS_PER_SEC))↵
#endif↵
~~~~~

~~~~~↵

with this u can get execution time of parts of your programm. Example:↵

~~~~~↵
int main () {↵
     time__("dfs time"){↵
          /* dfs code */↵
     }↵
}↵
~~~~~↵
And programm will print something like `dfs time : 0.265s`. You don't need to erase debugging part when you will submit it. Example submission: [submission:35088800]. ↵
Thank you for reading and I hope it will help you


История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский yhtyyar.s 2018-02-09 18:01:48 12
en3 Английский yhtyyar.s 2018-02-09 17:54:03 147 Tiny change: 'e)(clock()-blockTime)/CLOCKS_PER' -> 'e)(clock() - blockTime) / CLOCKS_PER'
en2 Английский yhtyyar.s 2018-02-09 15:19:14 548 Tiny change: ': false); debug("%s' -> ': false); debug("%s' (published)
en1 Английский yhtyyar.s 2018-02-09 14:50:45 921 Initial revision (saved to drafts)