1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/***************************************************************************
* blitz/bench.h Benchmark classes
*
* Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
*
* This code was relicensed under the modified BSD license for use in SciPy
* by Todd Veldhuizen (see LICENSE.txt in the weave directory).
*
*
* Suggestions: blitz-dev@oonumerics.org
* Bugs: blitz-bugs@oonumerics.org
*
* For more information, please see the Blitz++ Home Page:
* http://oonumerics.org/blitz/
*
***************************************************************************/
#ifndef BZ_BENCH_H
#define BZ_BENCH_H
#ifndef BZ_MATRIX_H
#include <blitz/matrix.h>
#endif
#ifndef BZ_TIMER_H
#include <blitz/timer.h>
#endif
#include <math.h>
BZ_NAMESPACE(blitz)
// Forward declaration
template<typename P_parameter = unsigned>
class BenchmarkImplementation;
// Declaration of class Benchmark<T>
// The template parameter T is the parameter type which is varied in
// the benchmark. Typically T will be an unsigned, and will represent
// the length of a vector, size of an array, etc.
template<typename P_parameter = unsigned>
class Benchmark {
public:
typedef P_parameter T_parameter;
Benchmark(unsigned numImplementations);
~Benchmark();
void addImplementation(BenchmarkImplementation<T_parameter>*
implementation);
void run(ostream& log = cout);
double getMflops(unsigned implementation, unsigned setting) const;
double getRate(unsigned implementation, unsigned setting) const;
void saveMatlabGraph(const char* filename) const;
public:
// Virtual functions
virtual const char* description() const
{ return ""; }
virtual const char* parameterDescription() const
{ return "Vector length"; }
virtual unsigned numParameterSettings() const
{ return 19; }
virtual T_parameter getParameterSetting(unsigned i) const
{ return ::pow(10.0, (i+1)/4.0); }
virtual long getIterationSetting(unsigned i) const
{ return 1000000L / getParameterSetting(i); }
private:
Benchmark(const Benchmark<P_parameter>&) { }
void operator=(const Benchmark<P_parameter>&) { }
enum { uninitialized, initialized, running, done } state_;
unsigned numImplementations_;
unsigned numStoredImplementations_;
BenchmarkImplementation<T_parameter>** implementations_;
Matrix<double,RowMajor> rates_; // Iterations per second array
Matrix<double,RowMajor> Mflops_;
};
template<typename P_parameter>
class BenchmarkImplementation {
public:
typedef P_parameter T_parameter;
virtual void initialize(P_parameter parameter) { }
virtual void done() { }
virtual const char* implementationName() const
{ return ""; }
virtual void run(long iterations) = 0;
virtual void runOverhead(long iterations)
{
for (long i=0; i < iterations; ++i)
{
}
};
virtual void tickle() { }
virtual long flopsPerIteration() const
{ return 0; }
};
BZ_NAMESPACE_END
#include <blitz/bench.cc>
#endif // BZ_BENCH_H
|