[C++] Tic Toc function (Matlab-style)

This needs to introduction. While drinking milk i finally figured out the holy grail of C++, possibly the most universal and useful function i have ever written in any language. It formulates itself in practically three lines of code. Put the following outside the main():

  1. double tt_tic=0;
  3. void tic(){
  4. 	tt_tic = getTickCount();
  5. }
  6. void toc(){
  7. 	double tt_toc = (getTickCount() - tt_tic)/(getTickFrequency());
  8. 	printf ("toc: %4.3f sn", tt_toc);
  9. }

seriously, if you Google for “tic toc c++” you will get people writing on for ages in which way you can do this, instead of just posting the code. So here it is.

TADAA! Matlab-style tictoc functionality! You request it in your code (duh) just by stating “tic();” and then “toc();”. Also, all my code is licenced under a Creative Commons licence. This code on the other hand I have licenced under a beerware licence (http://en.wikipedia.org/wiki/Beerware). Just so you know.

Tim Zaman

MSc Biorobotics. Specialization in computer vision and deep learning. Works at NVIDIA.

You may also like...

1 Response

  1. MRM says:

    Thanx man. You are my hero:)