extracted BigO and GetBigO in own file

This commit is contained in:
Ismael 2016-05-23 22:31:40 +02:00
parent 266b3bd635
commit 0c23d2852f
4 changed files with 43 additions and 34 deletions

View file

@ -154,6 +154,7 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
#include <stdint.h>
#include "macros.h"
#include "complexity.h"
namespace benchmark {
class BenchmarkReporter;
@ -231,20 +232,6 @@ enum TimeUnit {
kMillisecond
};
// BigO is passed to a benchmark in order to specify the asymptotic computational
// complexity for the benchmark. In case oAuto is selected, complexity will be
// calculated automatically to the best fit.
enum BigO {
oNone,
o1,
oN,
oNSquared,
oNCubed,
oLogN,
oNLogN,
oAuto
};
// State is passed to a running Benchmark and contains state for the
// benchmark to use.
class State {

View file

@ -0,0 +1,42 @@
#ifndef COMPLEXITY_H_
#define COMPLEXITY_H_
#include <string>
namespace benchmark {
// BigO is passed to a benchmark in order to specify the asymptotic computational
// complexity for the benchmark. In case oAuto is selected, complexity will be
// calculated automatically to the best fit.
enum BigO {
oNone,
o1,
oN,
oNSquared,
oNCubed,
oLogN,
oNLogN,
oAuto
};
inline std::string GetBigO(BigO complexity) {
switch (complexity) {
case oN:
return "* N";
case oNSquared:
return "* N**2";
case oNCubed:
return "* N**3";
case oLogN:
return "* lgN";
case oNLogN:
return "* NlgN";
case o1:
return "* 1";
default:
return "";
}
}
} // end namespace benchmark
#endif // COMPLEXITY_H_

View file

@ -108,7 +108,6 @@ protected:
static void ComputeStats(const std::vector<Run> & reports, Run* mean, Run* stddev);
static void ComputeBigO(const std::vector<Run> & reports, Run* bigO, Run* rms);
static TimeUnitMultiplier GetTimeUnitAndMultiplier(TimeUnit unit);
static std::string GetBigO(BigO complexity);
};
// Simple reporter that outputs benchmark data to the console. This is the

View file

@ -128,25 +128,6 @@ void BenchmarkReporter::ComputeBigO(
rms->complexity = result_cpu.complexity;
}
std::string BenchmarkReporter::GetBigO(BigO complexity) {
switch (complexity) {
case oN:
return "* N";
case oNSquared:
return "* N**2";
case oNCubed:
return "* N**3";
case oLogN:
return "* lgN";
case oNLogN:
return "* NlgN";
case o1:
return "* 1";
default:
return "";
}
}
TimeUnitMultiplier BenchmarkReporter::GetTimeUnitAndMultiplier(TimeUnit unit) {
switch (unit) {
case kMillisecond: