Unverified Commit 64e5a13f by Dominic Hamon Committed by GitHub

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
parent 50ffc781
...@@ -385,7 +385,7 @@ enum BigO { oNone, o1, oN, oNSquared, oNCubed, oLogN, oNLogN, oAuto, oLambda }; ...@@ -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 // BigOFunc is passed to a benchmark in order to specify the asymptotic
// computational complexity for the benchmark. // 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 // StatisticsFunc is passed to a benchmark in order to compute some descriptive
// statistics over all the measurements of some type // statistics over all the measurements of some type
...@@ -1303,7 +1303,7 @@ class BenchmarkReporter { ...@@ -1303,7 +1303,7 @@ class BenchmarkReporter {
// Keep track of arguments to compute asymptotic complexity // Keep track of arguments to compute asymptotic complexity
BigO complexity; BigO complexity;
BigOFunc* complexity_lambda; BigOFunc* complexity_lambda;
int complexity_n; int64_t complexity_n;
// what statistics to compute from the measurements // what statistics to compute from the measurements
const std::vector<Statistics>* statistics; const std::vector<Statistics>* statistics;
......
...@@ -28,18 +28,18 @@ namespace benchmark { ...@@ -28,18 +28,18 @@ namespace benchmark {
BigOFunc* FittingCurve(BigO complexity) { BigOFunc* FittingCurve(BigO complexity) {
switch (complexity) { switch (complexity) {
case oN: case oN:
return [](int n) -> double { return n; }; return [](int64_t n) -> double { return n; };
case oNSquared: case oNSquared:
return [](int n) -> double { return std::pow(n, 2); }; return [](int64_t n) -> double { return std::pow(n, 2); };
case oNCubed: case oNCubed:
return [](int n) -> double { return std::pow(n, 3); }; return [](int64_t n) -> double { return std::pow(n, 3); };
case oLogN: case oLogN:
return [](int n) { return log2(n); }; return [](int64_t n) { return log2(n); };
case oNLogN: case oNLogN:
return [](int n) { return n * log2(n); }; return [](int64_t n) { return n * log2(n); };
case o1: case o1:
default: default:
return [](int) { return 1.0; }; return [](int64_t) { return 1.0; };
} }
} }
...@@ -68,12 +68,12 @@ std::string GetBigOString(BigO complexity) { ...@@ -68,12 +68,12 @@ std::string GetBigOString(BigO complexity) {
// given by the lambda expression. // given by the lambda expression.
// - n : Vector containing the size of the benchmark tests. // - n : Vector containing the size of the benchmark tests.
// - time : Vector containing the times for 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 // For a deeper explanation on the algorithm logic, look the README file at
// http://github.com/ismaelJimenez/Minimal-Cpp-Least-Squared-Fit // 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, const std::vector<double>& time,
BigOFunc* fitting_curve) { BigOFunc* fitting_curve) {
double sigma_gn = 0.0; double sigma_gn = 0.0;
...@@ -117,7 +117,7 @@ LeastSq MinimalLeastSq(const std::vector<int>& n, ...@@ -117,7 +117,7 @@ LeastSq MinimalLeastSq(const std::vector<int>& n,
// - complexity : If different than oAuto, the fitting curve will stick to // - complexity : If different than oAuto, the fitting curve will stick to
// this one. If it is oAuto, it will be calculated the best // this one. If it is oAuto, it will be calculated the best
// fitting curve. // 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) { const std::vector<double>& time, const BigO complexity) {
CHECK_EQ(n.size(), time.size()); CHECK_EQ(n.size(), time.size());
CHECK_GE(n.size(), 2); // Do not compute fitting curve is less than two CHECK_GE(n.size(), 2); // Do not compute fitting curve is less than two
...@@ -157,7 +157,7 @@ std::vector<BenchmarkReporter::Run> ComputeBigO( ...@@ -157,7 +157,7 @@ std::vector<BenchmarkReporter::Run> ComputeBigO(
if (reports.size() < 2) return results; if (reports.size() < 2) return results;
// Accumulators. // Accumulators.
std::vector<int> n; std::vector<int64_t> n;
std::vector<double> real_time; std::vector<double> real_time;
std::vector<double> cpu_time; std::vector<double> cpu_time;
......
...@@ -40,7 +40,7 @@ class ThreadManager { ...@@ -40,7 +40,7 @@ class ThreadManager {
double manual_time_used = 0; double manual_time_used = 0;
int64_t bytes_processed = 0; int64_t bytes_processed = 0;
int64_t items_processed = 0; int64_t items_processed = 0;
int complexity_n = 0; int64_t complexity_n = 0;
std::string report_label_; std::string report_label_;
std::string error_message_; std::string error_message_;
bool has_error_ = false; bool has_error_ = false;
......
...@@ -55,7 +55,7 @@ void BM_Complexity_O1(benchmark::State& state) { ...@@ -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::o1);
BENCHMARK(BM_Complexity_O1)->Range(1, 1 << 18)->Complexity(); 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; return 1.0;
}); });
...@@ -106,7 +106,7 @@ BENCHMARK(BM_Complexity_O_N) ...@@ -106,7 +106,7 @@ BENCHMARK(BM_Complexity_O_N)
BENCHMARK(BM_Complexity_O_N) BENCHMARK(BM_Complexity_O_N)
->RangeMultiplier(2) ->RangeMultiplier(2)
->Range(1 << 10, 1 << 16) ->Range(1 << 10, 1 << 16)
->Complexity([](int n) -> double { return n; }); ->Complexity([](int64_t n) -> double { return n; });
BENCHMARK(BM_Complexity_O_N) BENCHMARK(BM_Complexity_O_N)
->RangeMultiplier(2) ->RangeMultiplier(2)
->Range(1 << 10, 1 << 16) ->Range(1 << 10, 1 << 16)
...@@ -141,7 +141,7 @@ BENCHMARK(BM_Complexity_O_N_log_N) ...@@ -141,7 +141,7 @@ BENCHMARK(BM_Complexity_O_N_log_N)
BENCHMARK(BM_Complexity_O_N_log_N) BENCHMARK(BM_Complexity_O_N_log_N)
->RangeMultiplier(2) ->RangeMultiplier(2)
->Range(1 << 10, 1 << 16) ->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) BENCHMARK(BM_Complexity_O_N_log_N)
->RangeMultiplier(2) ->RangeMultiplier(2)
->Range(1 << 10, 1 << 16) ->Range(1 << 10, 1 << 16)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment