mirror of
https://github.com/google/benchmark.git
synced 2024-11-26 07:32:19 +00:00
extracted BigO and GetBigO in own file
This commit is contained in:
parent
266b3bd635
commit
0c23d2852f
|
@ -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 {
|
||||
|
|
42
include/benchmark/complexity.h
Normal file
42
include/benchmark/complexity.h
Normal 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_
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue