testClock.cpp

Description of class 'Clock'

Aim: To provide functions to start and stop a timer. Is useful to get performance of algorithms.

The following code snippet demonstrates how to use Clock

  #include <DGtal/utils/Clock.h>

   Clock c;
   long duration;

   c.startClock();
   ...
   //do something
   ...
   duration = c.stopClock();

   std::cout<< "Duration in ms. : "<< duration <<endl;
#include <cstdio>
#include <cmath>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/utils/Clock.h"

using namespace DGtal;
using namespace std;

bool test_minimalTick()
{
    double tick;
    Clock c;

    trace.info() << c <<std::endl;

    c.startClock();
    tick = c.stopClock();
    trace.info() << "Minimal tick: "<< tick <<endl;
    return (tick >= 0);
}

bool test_loopTick()
{
    double tick,tmp=0;

    Clock c;
    c.startClock();
    for (unsigned int i=0 ; i< 4334450; i++)
        tmp = cos(tmp+i);

    tick = c.stopClock();
    trace.info()<< "Loop tick: "<< tick <<endl;
    return (tick >= 0);
}

bool test_MultipleLoop()
{
    double tick1,tick2,tmp=0;

    Clock c;
    c.startClock();
    for (unsigned int i=0 ; i< 4334450; i++)
        tmp = cos(tmp+i);

    Clock c2;
    c2.startClock();
    for (unsigned int i=0 ; i< 4334450; i++)
        tmp = cos(tmp+i);

    tick2 = c2.stopClock();

    for (unsigned int i=0 ; i< 4334450; i++)
        tmp = cos(tmp+i);

    tick1 = c.stopClock();
    trace.info()<< "Loop tick1: "<< tick1 <<" Loop tick2: "<< tick2 <<endl;
    return (tick1 >= 0);
}


int main()
{
    if (test_minimalTick() && test_loopTick() && test_MultipleLoop())
        return 0;
    else
        return 1;

}
Generated on Wed Sep 29 15:53:45 2010 for DGtal by  doxygen 1.6.3