Version 1 (modified by sam, 10 years ago) (diff)

try to document the Timer class

Table of Contents

  1. Timer

<lol/sys/timer.h>

View this file in the source browser: trunk/src/lol/sys/timer.h

Timer

The Timer class encapsulates a high-resolution timer.

A timer starts to measure time as soon as it is created.

Timer::Timer();
Timer::~Timer();

float Timer::Poll();
float Timer::Get();
void Timer::Wait(float seconds);

Use Timer::Poll() to query the elapsed time in seconds.

Timer t;
op1();
printf("First operation took %f seconds\n", t.Poll());
op2();
printf("Total time for all operations: %f seconds\n", t.Poll());

Use Timer::Get() to query the elapsed time while at the same time setting it back to zero.

Timer t;
op1();
printf("First operation took %f seconds\n", t.Get());
op2();
printf("Second operation took %f seconds\n", t.Get());

Use Timer::Wait() to wait until the elapsed time reaches a certain value. This function does not reset the current timer value because a call to Timer::Get() is necessary to know how much time we spent.

Timer t;
send_work();
while (!work_finished())
    t.Wait(0.01f);
printf("The work took approximately %f seconds\n", t.Get());