\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)
CGAL 4.6.1 - Profiling tools, Hash Map, Union-find, Modifiers
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages

#include <CGAL/Profile_counter.h>

Definition

The class Profile_counter provides a way to count the number of times a given line of code is executed during the execution of a program, and print this number at the end of the execution of the program.

Such counters can be added at critical places in the code, and at the end of the execution of a program, the count is printed on std::cerr, together with an identification string passed to the constructor. The macro CGAL_PROFILER can be used to conveniently place these counters anywhere. They are disabled by default and activated by the global macro CGAL_PROFILE.

Operations

If CGAL_PROFILE is not defined, then CGAL_PROFILER is defined to an empty statement. Otherwise, it is defined to

{ static CGAL::Profile_counter tmp(MSG); ++tmp; }


File Profiling_tools/Profile_counter.cpp

#define CGAL_PROFILE
#include <CGAL/Profile_counter.h>
int main()
{
for (int i=0; i<10; ++i)
{
CGAL_PROFILER("iterations of the for-loop");
}
return 0;
}

will print at exit:

[CGAL::Profile_counter] 10 iterations of the for-loop

Related Functions

(Note that these are not member functions.)

#define CGAL_PROFILE
 Macro to enable and disable profiling statements.
 
#define CGAL_PROFILER(MSG)
 Profiling macro that uses CGAL::Profile_counter.
 

Creation

 Profile_counter (std::string s)
 The internal counter is initialized to 0, and the string s is stored for further printing by the destructor.
 
 ~Profile_counter ()
 The value of the counter is printed to std::cerr together with the string.
 

Operations

void operator++ ()
 Increments the internal counter.