Calculating execution time in c++

Revision en1, by yhtyyar.s, 2018-02-09 14:50:45

Hi Codeforces. Today i saw GreenGrape solution of the problem D. Robot Vacuum Cleaner : solution. 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 directive

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

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English yhtyyar.s 2018-02-09 18:01:48 12
en3 English yhtyyar.s 2018-02-09 17:54:03 147 Tiny change: 'e)(clock()-blockTime)/CLOCKS_PER' -> 'e)(clock() - blockTime) / CLOCKS_PER'
en2 English yhtyyar.s 2018-02-09 15:19:14 548 Tiny change: ': false); debug("%s' -> ': false); debug("%s' (published)
en1 English yhtyyar.s 2018-02-09 14:50:45 921 Initial revision (saved to drafts)