The Stopwach class provides a simple interace to allow timing function calls etc...
It is possible to stop the stopwatch for an indefinite amount of time without losing the current elapsed time period, allowing it to be used to calculate the actual amount of time a function spends performing a task without taking into account e.g. time spent being blocked by a mutex. The class is exported to python in the cadabra2 module as Stopwatch.
Example C++ usage:
#include <iostream>
#include <vector>
void do_other_stuff() { std::cout << "Doing other stuff\n"; }
{
const int n = 1000;
std::vector<int> v;
for (unsigned int i = 0; i < n; ++i)
v.push_back(i);
do_other_stuff();
for (unsigned int i = n; i > 0; --i)
v.push_back(i);
std::cout << "Total time spent pushing to vector and not spent doing other stuff: " << s << '\n';
s.start();
do_other_stuff();
s.stop();
std::cout << "Doing other stuff takes " << s.useconds() << "us\n";
return 0;
}
The Stopwach class provides a simple interace to allow timing function calls etc.....
Definition: Stopwatch.hh:107
void reset()
Reset to no-time-elapsed.
Definition: Stopwatch.cc:29
void start()
Continue timing (does not reset).
Definition: Stopwatch.cc:35
void stop()
Stop timing.
Definition: Stopwatch.cc:41
Example python usage:
from cadabra2 import Stopwatch
def do_other_stuff():
print("Doing other stuff")
n = 1000
v = []
s.start()
for i in range(n):
v += [i]
s.stop()
do_other_stuff()
s.start()
for i in range(n, 0, -1):
v += [i]
s.stop()
print("Total time spent pushing to vector and not spent doing other stuff: {}".format(s))
s.reset()
s.start()
do_other_stuff()
s.stop()
print("Doing other stuff takes {}us".format(s.useconds()))