Skip to content

Commit

Permalink
Fix complexity int64 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dmah42 committed Mar 8, 2018
1 parent 39ea01d commit 10e5aca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,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 @@ -598,7 +598,7 @@ class State {
size_t bytes_processed_;
size_t items_processed_;

int complexity_n_;
int64_t complexity_n_;

public:
// Container for user-defined counters.
Expand Down
6 changes: 6 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ TEST_COPTS = [
"-pedantic",
"-pedantic-errors",
"-std=c++11",
"-Wall",
"-Wextra",
"-Wshadow",
# "-Wshorten-64-to-32",
"-Wfloat-equal",
"-fstrict-aliasing",
] + have_regex_copts()

PER_SRC_COPTS = ({
Expand Down
10 changes: 5 additions & 5 deletions test/complexity_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ ADD_COMPLEXITY_CASES(big_o_1_test_name, rms_o_1_test_name, lambda_big_o_1);
// --------------------------- Testing BigO O(N) --------------------------- //
// ========================================================================= //

std::vector<int> ConstructRandomVector(int size) {
std::vector<int> v;
std::vector<int64_t> ConstructRandomVector(int64_t size) {
std::vector<int64_t> v;
v.reserve(size);
for (int i = 0; i < size; ++i) {
for (int64_t i = 0; i < size; ++i) {
v.push_back(std::rand() % size);
}
return v;
}

void BM_Complexity_O_N(benchmark::State& state) {
auto v = ConstructRandomVector(state.range(0));
const int item_not_in_vector =
state.range(0) * 2; // Test worst case scenario (item not in vector)
// Test worst case scenario (item not in vector)
const int64_t item_not_in_vector = state.range(0) * 2;
for (auto _ : state) {
benchmark::DoNotOptimize(std::find(v.begin(), v.end(), item_not_in_vector));
}
Expand Down

0 comments on commit 10e5aca

Please sign in to comment.