MoochoPack: Miscellaneous Utilities for MOOCHO
Version of the Day
|
Helper class that takes care of timing. More...
#include <ProfileHackPack_profile_hack.hpp>
Public Member Functions | |
ProfileTiming (const std::string &func_name, std::ostream *out=NULL) | |
~ProfileTiming () | |
Helper class that takes care of timing.
Here is a simple program that uses these this class:
#include <iostream> int main() { #ifdef USE_PROFILE_HACK ProfileHackPack::ProfileTiming profile_timing("main()",&std::cout); #endif for( int i = 0; i < 10; ++i ) { f(); g(); } return 0; // When main() exists, the destructor for profile_timing will // record the time and will print the total times and number of // calls for "main()", "f()" and "g()" to <tt>std::cout</tt>. } void f() { #ifdef USE_PROFILE_HACK ProfileHackPack::ProfileTiming profile_timing("f()"); #endif ... // When f() exists, the destructor for profile_timing will record the // time for this function call and increment the number of calls to this // function. } void g() { #ifdef USE_PROFILE_HACK ProfileHackPack::ProfileTiming profile_timing("g()"); #endif ... // When g() exists, the destructor for profile_timing will record the // time for this function call and increment the number of calls to this // function. }
ToDo: Show an example of the output that might be generated for the above program.
In the above program, if USE_PROFILE_HACK
is not defined, then there will be no runtime performance penalty and no profiling results will be printed.
This class collects timings for an entire process and should work properly in a multi-threaded application.
Definition at line 123 of file ProfileHackPack_profile_hack.hpp.
|
inline |
func_name | The name of the function to be timed |
out | If != NULL then the function times will be printed to this stream when object is destroyed. |
Definition at line 131 of file ProfileHackPack_profile_hack.hpp.
|
inline |
Definition at line 138 of file ProfileHackPack_profile_hack.hpp.