Skip to content

Commit ebba6ca

Browse files
authored
Merge 9dcdd39 into 9f5694c
2 parents 9f5694c + 9dcdd39 commit ebba6ca

File tree

9 files changed

+87
-85
lines changed

9 files changed

+87
-85
lines changed

include/benchmark/benchmark.h

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ enum BigO { oNone, o1, oN, oNSquared, oNCubed, oLogN, oNLogN, oAuto, oLambda };
379379

380380
// BigOFunc is passed to a benchmark in order to specify the asymptotic
381381
// computational complexity for the benchmark.
382-
typedef double(BigOFunc)(int);
382+
typedef double(BigOFunc)(int64_t);
383383

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

521521
BENCHMARK_ALWAYS_INLINE
522-
int complexity_length_n() { return complexity_n_; }
522+
int64_t complexity_length_n() { return complexity_n_; }
523523

524524
// If this routine is called with items > 0, then an items/s
525525
// label is printed on the benchmark report line for the currently
@@ -553,16 +553,16 @@ class State {
553553

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

561561
BENCHMARK_DEPRECATED_MSG("use 'range(0)' instead")
562-
int range_x() const { return range(0); }
562+
int64_t range_x() const { return range(0); }
563563

564564
BENCHMARK_DEPRECATED_MSG("use 'range(1)' instead")
565-
int range_y() const { return range(1); }
565+
int64_t range_y() const { return range(1); }
566566

567567
BENCHMARK_ALWAYS_INLINE
568568
size_t iterations() const { return (max_iterations - total_iterations_) + 1; }
@@ -572,12 +572,12 @@ class State {
572572
bool finished_;
573573
size_t total_iterations_;
574574

575-
std::vector<int> range_;
575+
std::vector<int64_t> range_;
576576

577577
size_t bytes_processed_;
578578
size_t items_processed_;
579579

580-
int complexity_n_;
580+
int64_t complexity_n_;
581581

582582
bool error_occurred_;
583583

@@ -591,7 +591,7 @@ class State {
591591
const size_t max_iterations;
592592

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

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

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

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

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

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

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

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

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

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

824824
int ArgsCnt() const;
825825

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

828829
private:
829830
friend class BenchmarkFamilies;
830831

831832
std::string name_;
832833
ReportMode report_mode_;
833834
std::vector<std::string> arg_names_; // Args for all benchmark runs
834-
std::vector<std::vector<int> > args_; // Args for all benchmark runs
835+
std::vector<std::vector<int64_t> > args_; // Args for all benchmark runs
835836
TimeUnit time_unit_;
836-
int range_multiplier_;
837+
int64_t range_multiplier_;
837838
double min_time_;
838839
size_t iterations_;
839840
int repetitions_;
@@ -1239,7 +1240,7 @@ class BenchmarkReporter {
12391240
// Keep track of arguments to compute asymptotic complexity
12401241
BigO complexity;
12411242
BigOFunc* complexity_lambda;
1242-
int complexity_n;
1243+
int64_t complexity_n;
12431244

12441245
// what statistics to compute from the measurements
12451246
const std::vector<Statistics>* statistics;

src/benchmark.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ThreadManager {
142142
double manual_time_used = 0;
143143
int64_t bytes_processed = 0;
144144
int64_t items_processed = 0;
145-
int complexity_n = 0;
145+
int64_t complexity_n = 0;
146146
std::string report_label_;
147147
std::string error_message_;
148148
bool has_error_ = false;
@@ -394,7 +394,7 @@ std::vector<BenchmarkReporter::Run> RunBenchmark(
394394
} // namespace
395395
} // namespace internal
396396

397-
State::State(size_t max_iters, const std::vector<int>& ranges, int thread_i,
397+
State::State(size_t max_iters, const std::vector<int64_t>& ranges, int thread_i,
398398
int n_threads, internal::ThreadTimer* timer,
399399
internal::ThreadManager* manager)
400400
: started_(false),

src/benchmark_api_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ struct Benchmark::Instance {
1717
std::string name;
1818
Benchmark* benchmark;
1919
ReportMode report_mode;
20-
std::vector<int> arg;
20+
std::vector<int64_t> arg;
2121
TimeUnit time_unit;
22-
int range_multiplier;
22+
int64_t range_multiplier;
2323
bool use_real_time;
2424
bool use_manual_time;
2525
BigO complexity;

src/benchmark_register.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ bool BenchmarkFamilies::FindBenchmarks(
173173
StringPrintF("%s:", family->arg_names_[arg_i].c_str());
174174
}
175175
}
176-
176+
177177
instance.name += StringPrintF("%d", arg);
178178
++arg_i;
179179
}
@@ -244,7 +244,8 @@ Benchmark::Benchmark(const char* name)
244244

245245
Benchmark::~Benchmark() {}
246246

247-
void Benchmark::AddRange(std::vector<int>* dst, int lo, int hi, int mult) {
247+
template<typename Z>
248+
void Benchmark::AddRange(std::vector<Z>* dst, Z lo, Z hi, Z mult) {
248249
CHECK_GE(lo, 0);
249250
CHECK_GE(hi, lo);
250251
CHECK_GE(mult, 2);
@@ -267,7 +268,7 @@ void Benchmark::AddRange(std::vector<int>* dst, int lo, int hi, int mult) {
267268
}
268269
}
269270

270-
Benchmark* Benchmark::Arg(int x) {
271+
Benchmark* Benchmark::Arg(int64_t x) {
271272
CHECK(ArgsCnt() == -1 || ArgsCnt() == 1);
272273
args_.push_back({x});
273274
return this;
@@ -278,20 +279,20 @@ Benchmark* Benchmark::Unit(TimeUnit unit) {
278279
return this;
279280
}
280281

281-
Benchmark* Benchmark::Range(int start, int limit) {
282+
Benchmark* Benchmark::Range(int64_t start, int64_t limit) {
282283
CHECK(ArgsCnt() == -1 || ArgsCnt() == 1);
283-
std::vector<int> arglist;
284+
std::vector<int64_t> arglist;
284285
AddRange(&arglist, start, limit, range_multiplier_);
285286

286-
for (int i : arglist) {
287+
for (int64_t i : arglist) {
287288
args_.push_back({i});
288289
}
289290
return this;
290291
}
291292

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

304305
for (std::size_t i = 0; i < total; i++) {
305-
std::vector<int> tmp;
306+
std::vector<int64_t> tmp;
306307
tmp.reserve(arglists.size());
307308

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

337-
Benchmark* Benchmark::DenseRange(int start, int limit, int step) {
338+
Benchmark* Benchmark::DenseRange(int64_t start, int64_t limit, int64_t step) {
338339
CHECK(ArgsCnt() == -1 || ArgsCnt() == 1);
339340
CHECK_GE(start, 0);
340341
CHECK_LE(start, limit);
341-
for (int arg = start; arg <= limit; arg += step) {
342+
for (int64_t arg = start; arg <= limit; arg += step) {
342343
args_.push_back({arg});
343344
}
344345
return this;
345346
}
346347

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

358-
Benchmark* Benchmark::RangeMultiplier(int multiplier) {
359+
Benchmark* Benchmark::RangeMultiplier(int64_t multiplier) {
359360
CHECK(multiplier > 1);
360361
range_multiplier_ = multiplier;
361362
return this;
@@ -439,7 +440,7 @@ Benchmark* Benchmark::DenseThreadRange(int min_threads, int max_threads,
439440
CHECK_GE(max_threads, min_threads);
440441
CHECK_GE(stride, 1);
441442

442-
for (auto i = min_threads; i < max_threads; i += stride) {
443+
for (int i = min_threads; i < max_threads; i += stride) {
443444
thread_counts_.push_back(i);
444445
}
445446
thread_counts_.push_back(max_threads);

src/complexity.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ namespace benchmark {
2828
BigOFunc* FittingCurve(BigO complexity) {
2929
switch (complexity) {
3030
case oN:
31-
return [](int n) -> double { return n; };
31+
return [](int64_t n) -> double { return 1.0*n; };
3232
case oNSquared:
33-
return [](int n) -> double { return std::pow(n, 2); };
33+
return [](int64_t n) -> double { return std::pow(1.0*n, 2); };
3434
case oNCubed:
35-
return [](int n) -> double { return std::pow(n, 3); };
35+
return [](int64_t n) -> double { return std::pow(1.0*n, 3); };
3636
case oLogN:
37-
return [](int n) { return log2(n); };
37+
return [](int64_t n) { return log2(1.0*n); };
3838
case oNLogN:
39-
return [](int n) { return n * log2(n); };
39+
return [](int64_t n) { return n * log2(1.0*n); };
4040
case o1:
4141
default:
42-
return [](int) { return 1.0; };
42+
return [](int64_t) { return 1.0; };
4343
}
4444
}
4545

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

76-
LeastSq MinimalLeastSq(const std::vector<int>& n,
76+
LeastSq MinimalLeastSq(const std::vector<int64_t>& n,
7777
const std::vector<double>& time,
7878
BigOFunc* fitting_curve) {
7979
double sigma_gn = 0.0;
@@ -117,7 +117,7 @@ LeastSq MinimalLeastSq(const std::vector<int>& n,
117117
// - complexity : If different than oAuto, the fitting curve will stick to
118118
// this one. If it is oAuto, it will be calculated the best
119119
// fitting curve.
120-
LeastSq MinimalLeastSq(const std::vector<int>& n,
120+
LeastSq MinimalLeastSq(const std::vector<int64_t>& n,
121121
const std::vector<double>& time, const BigO complexity) {
122122
CHECK_EQ(n.size(), time.size());
123123
CHECK_GE(n.size(), 2); // Do not compute fitting curve is less than two
@@ -157,7 +157,7 @@ std::vector<BenchmarkReporter::Run> ComputeBigO(
157157
if (reports.size() < 2) return results;
158158

159159
// Accumulators.
160-
std::vector<int> n;
160+
std::vector<int64_t> n;
161161
std::vector<double> real_time;
162162
std::vector<double> cpu_time;
163163

0 commit comments

Comments
 (0)