2005-10-26 00:38:49 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// The Loki Library
|
|
|
|
|
// Copyright (c) 2005 Peter K<>mmel
|
|
|
|
|
// Permission to use, copy, modify, distribute and sell this software for any
|
|
|
|
|
// purpose is hereby granted without fee, provided that the above copyright
|
|
|
|
|
// notice appear in all copies and that both that copyright notice and this
|
|
|
|
|
// permission notice appear in supporting documentation.
|
|
|
|
|
// The authors make no representations about the
|
|
|
|
|
// suitability of this software for any purpose. It is provided "as is"
|
|
|
|
|
// without express or implied warranty.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
#ifndef LOKI_TEST_TIMER_H
|
|
|
|
|
#define LOKI_TEST_TIMER_H
|
|
|
|
|
|
2006-10-17 20:36:13 +00:00
|
|
|
|
// $Id$
|
|
|
|
|
|
2005-10-26 00:38:49 +00:00
|
|
|
|
|
2005-08-27 13:05:20 +00:00
|
|
|
|
#include <ctime>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
|
|
class Timer
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
Timer()
|
|
|
|
|
{
|
|
|
|
|
t100 = 0;
|
|
|
|
|
};
|
2005-08-27 13:05:20 +00:00
|
|
|
|
|
|
|
|
|
void start()
|
2005-10-30 14:03:23 +00:00
|
|
|
|
{
|
|
|
|
|
t0 = clock();
|
|
|
|
|
}
|
2005-08-27 13:05:20 +00:00
|
|
|
|
|
|
|
|
|
void stop()
|
2005-10-30 14:03:23 +00:00
|
|
|
|
{
|
|
|
|
|
t1 = clock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int t()
|
|
|
|
|
{
|
|
|
|
|
return t1-t0;
|
|
|
|
|
}
|
2005-08-27 13:05:20 +00:00
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
double sec(int t)
|
|
|
|
|
{
|
|
|
|
|
return floor(100.0*double(t)/1000.0 )/100.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rel(int t)
|
|
|
|
|
{
|
2006-01-19 23:11:57 +00:00
|
|
|
|
return ( t100==0 ? 100 : static_cast<int>(floor(100.0*t/t100+0.5)) );
|
2005-10-30 14:03:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double speedup(int t)
|
|
|
|
|
{
|
|
|
|
|
double tup=t;
|
|
|
|
|
return (tup!=0 ? floor(100.0*(t100!=0?t100:tup)/tup+0.5)/100 : 1);
|
|
|
|
|
}
|
2005-08-27 13:05:20 +00:00
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
double t100;
|
2005-08-27 13:05:20 +00:00
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
void print(int t, const char* s)
|
|
|
|
|
{
|
2005-10-26 00:33:06 +00:00
|
|
|
|
std::cout << s << "\tseconds: " << sec(t) << "\trelative time: " << rel(t) << "%\tspeed-up factor: " << speedup(t) << "" << std::endl;
|
2005-10-30 14:03:23 +00:00
|
|
|
|
}
|
2005-08-27 13:05:20 +00:00
|
|
|
|
private:
|
|
|
|
|
int t0;
|
2005-10-30 14:03:23 +00:00
|
|
|
|
int t1;
|
2005-08-27 13:05:20 +00:00
|
|
|
|
};
|
2005-10-26 00:38:49 +00:00
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|