2005-08-27 13:05:20 +00:00
|
|
|
#include <ctime>
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
class Timer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Timer()
|
|
|
|
{
|
|
|
|
t100 = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void start()
|
|
|
|
{
|
|
|
|
t0 = clock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void stop()
|
|
|
|
{
|
|
|
|
t1 = clock();
|
|
|
|
}
|
|
|
|
|
|
|
|
int t()
|
|
|
|
{
|
|
|
|
return t1-t0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double sec(int t)
|
|
|
|
{
|
2005-10-06 10:17:56 +00:00
|
|
|
return floor(100.0*double(t)/1000.0 )/100.0;
|
2005-08-27 13:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int rel(int t)
|
|
|
|
{
|
|
|
|
return ( t100==0 ? 100 : (int) floor(100.0*t/t100+0.5) );
|
|
|
|
}
|
2005-10-06 10:17:56 +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
|
|
|
|
|
|
|
double t100;
|
|
|
|
|
|
|
|
void print(int t, const char* s)
|
|
|
|
{
|
2005-10-06 10:17:56 +00:00
|
|
|
std::cout << s <<"\trelative time: " << rel(t) << "%\tspeed-up factor: " << speedup(t) << "" << std::endl;
|
2005-08-27 13:05:20 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
int t0;
|
|
|
|
int t1;
|
|
|
|
};
|