[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....

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
2
3
4
5
6
7
8
9
double tt_tic=0;
 
void tic(){
	tt_tic = getTickCount();
}
void toc(){
	double tt_toc = (getTickCount() - tt_tic)/(getTickFrequency());
	printf ("toc: %4.3f s\n", tt_toc);
}

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.

About Tim Zaman

There's page about myself with some babble and pics on this site Here!. // R&D : Vision/Imaging | 2D/3D Image Processing | Robotics/Automation | Programming | Electronics | Open Source | And, obviously, Photography.

Creative Commons License
The [C++] Tic Toc function (Matlab-style) by Tim Zaman, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 3.0 Unported License.