Skip to content
Closed
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
47 changes: 24 additions & 23 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ enum BigO { oNone, o1, oN, oNSquared, oNCubed, oLogN, oNLogN, oAuto, oLambda };

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

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

BENCHMARK_ALWAYS_INLINE
int complexity_length_n() { return complexity_n_; }
int64_t complexity_length_n() { 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 @@ -553,16 +553,16 @@ class State {

// Range arguments for this run. CHECKs if the argument has been set.
BENCHMARK_ALWAYS_INLINE
int range(std::size_t pos = 0) const {
int64_t range(std::size_t pos = 0) const {
assert(range_.size() > pos);
return range_[pos];
}

BENCHMARK_DEPRECATED_MSG("use 'range(0)' instead")
int range_x() const { return range(0); }
int64_t range_x() const { return range(0); }

BENCHMARK_DEPRECATED_MSG("use 'range(1)' instead")
int range_y() const { return range(1); }
int64_t range_y() const { return range(1); }

BENCHMARK_ALWAYS_INLINE
size_t iterations() const { return (max_iterations - total_iterations_) + 1; }
Expand All @@ -572,12 +572,12 @@ class State {
bool finished_;
size_t total_iterations_;

std::vector<int> range_;
std::vector<int64_t> range_;

size_t bytes_processed_;
size_t items_processed_;

int complexity_n_;
int64_t complexity_n_;

bool error_occurred_;

Expand All @@ -591,7 +591,7 @@ class State {
const size_t max_iterations;

// TODO(EricWF) make me private
State(size_t max_iters, const std::vector<int>& ranges, int thread_i,
State(size_t max_iters, const std::vector<int64_t>& ranges, int thread_i,
int n_threads, internal::ThreadTimer* timer,
internal::ThreadManager* manager);

Expand Down Expand Up @@ -670,31 +670,31 @@ class Benchmark {
// Run this benchmark once with "x" as the extra argument passed
// to the function.
// REQUIRES: The function passed to the constructor must accept an arg1.
Benchmark* Arg(int x);
Benchmark* Arg(int64_t x);

// Run this benchmark with the given time unit for the generated output report
Benchmark* Unit(TimeUnit unit);

// Run this benchmark once for a number of values picked from the
// range [start..limit]. (start and limit are always picked.)
// REQUIRES: The function passed to the constructor must accept an arg1.
Benchmark* Range(int start, int limit);
Benchmark* Range(int64_t start, int64_t limit);

// Run this benchmark once for all values in the range [start..limit] with
// specific step
// REQUIRES: The function passed to the constructor must accept an arg1.
Benchmark* DenseRange(int start, int limit, int step = 1);
Benchmark* DenseRange(int64_t start, int64_t limit, int64_t step = 1);

// Run this benchmark once with "args" as the extra arguments passed
// to the function.
// REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
Benchmark* Args(const std::vector<int>& args);
Benchmark* Args(const std::vector<int64_t>& args);

// Equivalent to Args({x, y})
// NOTE: This is a legacy C++03 interface provided for compatibility only.
// New code should use 'Args'.
Benchmark* ArgPair(int x, int y) {
std::vector<int> args;
Benchmark* ArgPair(int64_t x, int64_t y) {
std::vector<int64_t> args;
args.push_back(x);
args.push_back(y);
return Args(args);
Expand All @@ -703,7 +703,7 @@ class Benchmark {
// Run this benchmark once for a number of values picked from the
// ranges [start..limit]. (starts and limits are always picked.)
// REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
Benchmark* Ranges(const std::vector<std::pair<int, int> >& ranges);
Benchmark* Ranges(const std::vector<std::pair<int64_t, int64_t> >& ranges);

// Equivalent to ArgNames({name})
Benchmark* ArgName(const std::string& name);
Expand All @@ -715,8 +715,8 @@ class Benchmark {
// Equivalent to Ranges({{lo1, hi1}, {lo2, hi2}}).
// NOTE: This is a legacy C++03 interface provided for compatibility only.
// New code should use 'Ranges'.
Benchmark* RangePair(int lo1, int hi1, int lo2, int hi2) {
std::vector<std::pair<int, int> > ranges;
Benchmark* RangePair(int64_t lo1, int64_t hi1, int64_t lo2, int64_t hi2) {
std::vector<std::pair<int64_t, int64_t> > ranges;
ranges.push_back(std::make_pair(lo1, hi1));
ranges.push_back(std::make_pair(lo2, hi2));
return Ranges(ranges);
Expand All @@ -729,7 +729,7 @@ class Benchmark {

// Set the range multiplier for non-dense range. If not called, the range
// multiplier kRangeMultiplier will be used.
Benchmark* RangeMultiplier(int multiplier);
Benchmark* RangeMultiplier(int64_t multiplier);

// Set the minimum amount of time to use when running this benchmark. This
// option overrides the `benchmark_min_time` flag.
Expand Down Expand Up @@ -823,17 +823,18 @@ class Benchmark {

int ArgsCnt() const;

static void AddRange(std::vector<int>* dst, int lo, int hi, int mult);
template<typename Z>
static void AddRange(std::vector<Z>* dst, Z lo, Z hi, Z mult);

private:
friend class BenchmarkFamilies;

std::string name_;
ReportMode report_mode_;
std::vector<std::string> arg_names_; // Args for all benchmark runs
std::vector<std::vector<int> > args_; // Args for all benchmark runs
std::vector<std::vector<int64_t> > args_; // Args for all benchmark runs
TimeUnit time_unit_;
int range_multiplier_;
int64_t range_multiplier_;
double min_time_;
size_t iterations_;
int repetitions_;
Expand Down Expand Up @@ -1239,7 +1240,7 @@ class BenchmarkReporter {
// Keep track of arguments to compute asymptotic complexity
BigO complexity;
BigOFunc* complexity_lambda;
int complexity_n;
int64_t complexity_n;

// what statistics to compute from the measurements
const std::vector<Statistics>* statistics;
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class ThreadManager {
double manual_time_used = 0;
int64_t bytes_processed = 0;
int64_t items_processed = 0;
int complexity_n = 0;
int64_t complexity_n = 0;
std::string report_label_;
std::string error_message_;
bool has_error_ = false;
Expand Down Expand Up @@ -394,7 +394,7 @@ std::vector<BenchmarkReporter::Run> RunBenchmark(
} // namespace
} // namespace internal

State::State(size_t max_iters, const std::vector<int>& ranges, int thread_i,
State::State(size_t max_iters, const std::vector<int64_t>& ranges, int thread_i,
int n_threads, internal::ThreadTimer* timer,
internal::ThreadManager* manager)
: started_(false),
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ struct Benchmark::Instance {
std::string name;
Benchmark* benchmark;
ReportMode report_mode;
std::vector<int> arg;
std::vector<int64_t> arg;
TimeUnit time_unit;
int range_multiplier;
int64_t range_multiplier;
bool use_real_time;
bool use_manual_time;
BigO complexity;
Expand Down
31 changes: 16 additions & 15 deletions src/benchmark_register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ bool BenchmarkFamilies::FindBenchmarks(
StringPrintF("%s:", family->arg_names_[arg_i].c_str());
}
}

instance.name += StringPrintF("%d", arg);
++arg_i;
}
Expand Down Expand Up @@ -244,7 +244,8 @@ Benchmark::Benchmark(const char* name)

Benchmark::~Benchmark() {}

void Benchmark::AddRange(std::vector<int>* dst, int lo, int hi, int mult) {
template<typename Z>
void Benchmark::AddRange(std::vector<Z>* dst, Z lo, Z hi, Z mult) {
CHECK_GE(lo, 0);
CHECK_GE(hi, lo);
CHECK_GE(mult, 2);
Expand All @@ -267,7 +268,7 @@ void Benchmark::AddRange(std::vector<int>* dst, int lo, int hi, int mult) {
}
}

Benchmark* Benchmark::Arg(int x) {
Benchmark* Benchmark::Arg(int64_t x) {
CHECK(ArgsCnt() == -1 || ArgsCnt() == 1);
args_.push_back({x});
return this;
Expand All @@ -278,20 +279,20 @@ Benchmark* Benchmark::Unit(TimeUnit unit) {
return this;
}

Benchmark* Benchmark::Range(int start, int limit) {
Benchmark* Benchmark::Range(int64_t start, int64_t limit) {
CHECK(ArgsCnt() == -1 || ArgsCnt() == 1);
std::vector<int> arglist;
std::vector<int64_t> arglist;
AddRange(&arglist, start, limit, range_multiplier_);

for (int i : arglist) {
for (int64_t i : arglist) {
args_.push_back({i});
}
return this;
}

Benchmark* Benchmark::Ranges(const std::vector<std::pair<int, int>>& ranges) {
CHECK(ArgsCnt() == -1 || ArgsCnt() == static_cast<int>(ranges.size()));
std::vector<std::vector<int>> arglists(ranges.size());
Benchmark* Benchmark::Ranges(const std::vector<std::pair<int64_t, int64_t>>& ranges) {
CHECK(ArgsCnt() == -1 || ArgsCnt() == static_cast<int64_t>(ranges.size()));
std::vector<std::vector<int64_t>> arglists(ranges.size());
std::size_t total = 1;
for (std::size_t i = 0; i < ranges.size(); i++) {
AddRange(&arglists[i], ranges[i].first, ranges[i].second,
Expand All @@ -302,7 +303,7 @@ Benchmark* Benchmark::Ranges(const std::vector<std::pair<int, int>>& ranges) {
std::vector<std::size_t> ctr(arglists.size(), 0);

for (std::size_t i = 0; i < total; i++) {
std::vector<int> tmp;
std::vector<int64_t> tmp;
tmp.reserve(arglists.size());

for (std::size_t j = 0; j < arglists.size(); j++) {
Expand Down Expand Up @@ -334,17 +335,17 @@ Benchmark* Benchmark::ArgNames(const std::vector<std::string>& names) {
return this;
}

Benchmark* Benchmark::DenseRange(int start, int limit, int step) {
Benchmark* Benchmark::DenseRange(int64_t start, int64_t limit, int64_t step) {
CHECK(ArgsCnt() == -1 || ArgsCnt() == 1);
CHECK_GE(start, 0);
CHECK_LE(start, limit);
for (int arg = start; arg <= limit; arg += step) {
for (int64_t arg = start; arg <= limit; arg += step) {
args_.push_back({arg});
}
return this;
}

Benchmark* Benchmark::Args(const std::vector<int>& args) {
Benchmark* Benchmark::Args(const std::vector<int64_t>& args) {
CHECK(ArgsCnt() == -1 || ArgsCnt() == static_cast<int>(args.size()));
args_.push_back(args);
return this;
Expand All @@ -355,7 +356,7 @@ Benchmark* Benchmark::Apply(void (*custom_arguments)(Benchmark* benchmark)) {
return this;
}

Benchmark* Benchmark::RangeMultiplier(int multiplier) {
Benchmark* Benchmark::RangeMultiplier(int64_t multiplier) {
CHECK(multiplier > 1);
range_multiplier_ = multiplier;
return this;
Expand Down Expand Up @@ -439,7 +440,7 @@ Benchmark* Benchmark::DenseThreadRange(int min_threads, int max_threads,
CHECK_GE(max_threads, min_threads);
CHECK_GE(stride, 1);

for (auto i = min_threads; i < max_threads; i += stride) {
for (int i = min_threads; i < max_threads; i += stride) {
thread_counts_.push_back(i);
}
thread_counts_.push_back(max_threads);
Expand Down
18 changes: 9 additions & 9 deletions src/complexity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ namespace benchmark {
BigOFunc* FittingCurve(BigO complexity) {
switch (complexity) {
case oN:
return [](int n) -> double { return n; };
return [](int64_t n) -> double { return 1.0*n; };
case oNSquared:
return [](int n) -> double { return std::pow(n, 2); };
return [](int64_t n) -> double { return std::pow(1.0*n, 2); };
case oNCubed:
return [](int n) -> double { return std::pow(n, 3); };
return [](int64_t n) -> double { return std::pow(1.0*n, 3); };
case oLogN:
return [](int n) { return log2(n); };
return [](int64_t n) { return log2(1.0*n); };
case oNLogN:
return [](int n) { return n * log2(n); };
return [](int64_t n) { return n * log2(1.0*n); };
case o1:
default:
return [](int) { return 1.0; };
return [](int64_t) { return 1.0; };
}
}

Expand Down Expand Up @@ -73,7 +73,7 @@ std::string GetBigOString(BigO complexity) {
// For a deeper explanation on the algorithm logic, look the README file at
// http://github.com/ismaelJimenez/Minimal-Cpp-Least-Squared-Fit

LeastSq MinimalLeastSq(const std::vector<int>& n,
LeastSq MinimalLeastSq(const std::vector<int64_t>& n,
const std::vector<double>& time,
BigOFunc* fitting_curve) {
double sigma_gn = 0.0;
Expand Down Expand Up @@ -117,7 +117,7 @@ LeastSq MinimalLeastSq(const std::vector<int>& 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<int>& n,
LeastSq MinimalLeastSq(const std::vector<int64_t>& n,
const std::vector<double>& time, const BigO complexity) {
CHECK_EQ(n.size(), time.size());
CHECK_GE(n.size(), 2); // Do not compute fitting curve is less than two
Expand Down Expand Up @@ -157,7 +157,7 @@ std::vector<BenchmarkReporter::Run> ComputeBigO(
if (reports.size() < 2) return results;

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

Expand Down
Loading