Tuesday, October 18, 2011

Boost Timer

Boost Timer

If you have the boost library installed correctly on linux systems it should be sufficient to just add #include <boost/timer.hpp> or #include <boost/progress.hpp> depending on what you are looking for. There is a little more to it in a windows system, a quick google search on how to link library should point you in the right direction though.

So far I have just used the progress_timer. It is very nice in that as long as you create an instance of it upon your program completing it will print the execution time. You can also tell it to print the amount of time every so often and restart it, which is very useful in checking how long a certain function is taking to execute.

Here is a quick example of how I was using it.

progress_timer t;

start = t.elapsed();
correct = 0;
for(unsigned int i = 0; i < count; i++) { if (results[i] == data[i] * data[i]) { correct++; } } cout << "Second for loop took " << t.elapsed() - start << " seconds \n" << endl; cout << "Computed " << correct << "/" << count << " correct values" << endl; cout << "Computed " << 100.f * (float)correct/(float)count << "% correct values" << endl;


I imagine you can do something similar with the timer class.

No comments:

Post a Comment