Ensure 64-bit truncation doesn't happen for complexity_n (#569)

* Ensure 64-bit truncation doesn't happen for complexity results

* One more complexity_n 64-bit fix

* Missed another vector of int

* Piping through the int64_t
This commit is contained in:
Dominic Hamon 2018-04-12 15:40:24 +01:00 committed by GitHub
parent 50ffc781b1
commit 64e5a13fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 16 deletions

View File

@ -385,7 +385,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
@ -1303,7 +1303,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;

View File

@ -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 n; };
case oNSquared:
return [](int n) -> double { return std::pow(n, 2); };
return [](int64_t n) -> double { return std::pow(n, 2); };
case oNCubed:
return [](int n) -> double { return std::pow(n, 3); };
return [](int64_t n) -> double { return std::pow(n, 3); };
case oLogN:
return [](int n) { return log2(n); };
return [](int64_t n) { return log2(n); };
case oNLogN:
return [](int n) { return n * log2(n); };
return [](int64_t n) { return n * log2(n); };
case o1:
default:
return [](int) { return 1.0; };
return [](int64_t) { return 1.0; };
}
}
@ -68,12 +68,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. [](int n) {return n; };).
// - fitting_curve : lambda expression (e.g. [](int64_t n) {return n; };).
// 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;
@ -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
@ -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;

View File

@ -40,7 +40,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;

View File

@ -55,7 +55,7 @@ void BM_Complexity_O1(benchmark::State& state) {
}
BENCHMARK(BM_Complexity_O1)->Range(1, 1 << 18)->Complexity(benchmark::o1);
BENCHMARK(BM_Complexity_O1)->Range(1, 1 << 18)->Complexity();
BENCHMARK(BM_Complexity_O1)->Range(1, 1 << 18)->Complexity([](int) {
BENCHMARK(BM_Complexity_O1)->Range(1, 1 << 18)->Complexity([](int64_t) {
return 1.0;
});
@ -106,7 +106,7 @@ BENCHMARK(BM_Complexity_O_N)
BENCHMARK(BM_Complexity_O_N)
->RangeMultiplier(2)
->Range(1 << 10, 1 << 16)
->Complexity([](int n) -> double { return n; });
->Complexity([](int64_t n) -> double { return n; });
BENCHMARK(BM_Complexity_O_N)
->RangeMultiplier(2)
->Range(1 << 10, 1 << 16)
@ -141,7 +141,7 @@ BENCHMARK(BM_Complexity_O_N_log_N)
BENCHMARK(BM_Complexity_O_N_log_N)
->RangeMultiplier(2)
->Range(1 << 10, 1 << 16)
->Complexity([](int n) { return n * log2(n); });
->Complexity([](int64_t n) { return n * log2(n); });
BENCHMARK(BM_Complexity_O_N_log_N)
->RangeMultiplier(2)
->Range(1 << 10, 1 << 16)