Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] complexity_n is not of IterationCount type #1709

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,15 @@ typedef std::map<std::string, Counter> UserCounters;
// calculated automatically to the best fit.
enum BigO { oNone, o1, oN, oNSquared, oNCubed, oLogN, oNLogN, oAuto, oLambda };

typedef int64_t ComplexityN;

typedef int64_t IterationCount;

enum StatisticUnit { kTime, kPercentage };

// BigOFunc is passed to a benchmark in order to specify the asymptotic
// computational complexity for the benchmark.
typedef double(BigOFunc)(IterationCount);
typedef double(BigOFunc)(ComplexityN);

// StatisticsFunc is passed to a benchmark in order to compute some descriptive
// statistics over all the measurements of some type
Expand Down Expand Up @@ -875,10 +877,12 @@ class BENCHMARK_EXPORT State {
// and complexity_n will
// represent the length of N.
BENCHMARK_ALWAYS_INLINE
void SetComplexityN(int64_t complexity_n) { complexity_n_ = complexity_n; }
void SetComplexityN(ComplexityN complexity_n) {
complexity_n_ = complexity_n;
}

BENCHMARK_ALWAYS_INLINE
int64_t complexity_length_n() const { return complexity_n_; }
ComplexityN complexity_length_n() const { return complexity_n_; }

// If this routine is called with items > 0, then an items/s
// label is printed on the benchmark report line for the currently
Expand Down Expand Up @@ -967,7 +971,7 @@ class BENCHMARK_EXPORT State {
// items we don't need on the first cache line
std::vector<int64_t> range_;

int64_t complexity_n_;
ComplexityN complexity_n_;

public:
// Container for user-defined counters.
Expand Down Expand Up @@ -1805,7 +1809,7 @@ class BENCHMARK_EXPORT BenchmarkReporter {
// Keep track of arguments to compute asymptotic complexity
BigO complexity;
BigOFunc* complexity_lambda;
int64_t complexity_n;
ComplexityN complexity_n;

// what statistics to compute from the measurements
const std::vector<internal::Statistics>* statistics;
Expand Down
8 changes: 4 additions & 4 deletions src/complexity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ std::string GetBigOString(BigO complexity) {
// given by the lambda expression.
// - n : Vector containing the size of the benchmark tests.
// - time : Vector containing the times for the benchmark tests.
// - fitting_curve : lambda expression (e.g. [](int64_t n) {return n; };).
// - fitting_curve : lambda expression (e.g. [](ComplexityN n) {return n; };).

// For a deeper explanation on the algorithm logic, please refer to
// https://en.wikipedia.org/wiki/Least_squares#Least_squares,_regression_analysis_and_statistics

LeastSq MinimalLeastSq(const std::vector<int64_t>& n,
LeastSq MinimalLeastSq(const std::vector<ComplexityN>& n,
const std::vector<double>& time,
BigOFunc* fitting_curve) {
double sigma_gn_squared = 0.0;
Expand Down Expand Up @@ -124,7 +124,7 @@ LeastSq MinimalLeastSq(const std::vector<int64_t>& n,
// - complexity : If different than oAuto, the fitting curve will stick to
// this one. If it is oAuto, it will be calculated the best
// fitting curve.
LeastSq MinimalLeastSq(const std::vector<int64_t>& n,
LeastSq MinimalLeastSq(const std::vector<ComplexityN>& n,
const std::vector<double>& time, const BigO complexity) {
BM_CHECK_EQ(n.size(), time.size());
BM_CHECK_GE(n.size(), 2); // Do not compute fitting curve is less than two
Expand Down Expand Up @@ -164,7 +164,7 @@ std::vector<BenchmarkReporter::Run> ComputeBigO(
if (reports.size() < 2) return results;

// Accumulators.
std::vector<int64_t> n;
std::vector<ComplexityN> n;
std::vector<double> real_time;
std::vector<double> cpu_time;

Expand Down
Loading