MoochoPack: Miscellaneous Utilities for MOOCHO  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | List of all members
ProfileHackPack::ProfileTiming Class Reference

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 ()
 

Detailed Description

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.

Constructor & Destructor Documentation

ProfileHackPack::ProfileTiming::ProfileTiming ( const std::string &  func_name,
std::ostream *  out = NULL 
)
inline
Parameters
func_nameThe name of the function to be timed
outIf != 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.

ProfileHackPack::ProfileTiming::~ProfileTiming ( )
inline

Definition at line 138 of file ProfileHackPack_profile_hack.hpp.


The documentation for this class was generated from the following file: