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.16 Timer ( timer )<br />

1. Definition<br />

<strong>The</strong> class timer facilitates time measurements. An instance t has two states: running<br />

or stopped. It measures the time which elapses while it is in the state running. <strong>The</strong><br />

state depends on a (non-negative) internal counter, which is incremented by every start<br />

operation and decremented by every stop operation. <strong>The</strong> timer is running iff the counter<br />

is not zero. <strong>The</strong> use of a counter (instead of a boolean flag) to determine the state is<br />

helpful when a recursive function f is measured, which is shown in the example below:<br />

#include <br />

leda::timer f_timer;<br />

void f()<br />

{<br />

f_timer.start();<br />

// do something ...<br />

f(); // recursive call<br />

// do something else ...<br />

}<br />

f_timer.stop(); // timer is stopped when top-level call returns<br />

int main()<br />

{<br />

f();<br />

std::cout

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

Saved successfully!

Ooh no, something went wrong!