in matlab:
tic
do something ...
toc
my attempt to have this functionality:
#define tic double tic_t = clock();
#define toc std::cout << (clock() - tic_t)/CLOCKS_PER_SEC \
<< " seconds" << std::endl;
Now I can do this in C++:
tic
doSomething();
toc
The problem is that I cannot call it multiple times inside a function because tic_t will be defined several times.
I want to do something like this:
tic
doSomething1();
toc
tic
doSomething2();
toc
I’d implement it as a stack. Then, you can recurse, call it multiple times, do whatever you want, and it won’t break, so long as you call
toc()after everytic(). As a bonus, you don’t have to resort to using macros: