31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.17 Counter ( counter )<br />

1. Definition<br />

<strong>The</strong> class counter can be used during profiling to count how often certain code is executed.<br />

An example is given below.<br />

#include < <strong>LEDA</strong>/system/counter.h ><br />

2. Creation<br />

counter<br />

c(const string& name, bool report on destruction = true);<br />

creates an instance c with the given name. If report on destruction<br />

is true, then the counter reports its value upon destruction. <strong>The</strong><br />

initial value of the counter is zero.<br />

counter c; creates an unnamed instance c and sets the report on destruction<br />

flag to false. <strong>The</strong> initial value of the counter is zero.<br />

3. Operations<br />

void c.reset( ) sets the value of c to zero.<br />

void<br />

c.set value(const unsigned long val)<br />

sets the value of c to val.<br />

const unsigned long c.get value( ) returns the current value of c.<br />

const unsigned long c.increment( ) increments c and returns its new value. (We also provide<br />

the operator ++.)<br />

void<br />

c.set name(const string& name)<br />

sets the name of c.<br />

string c.get name( ) returns the name of c.<br />

void<br />

c.report on desctruction(bool do report = true)<br />

sets the flag report on destruction to do report.<br />

bool c.will report on desctruction( )<br />

4. Example<br />

returns whether c will issue a report upon its destruction.<br />

In the example below we count how often the function fibonacci is executed.<br />

#include

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!