Skip to content

Commit

Permalink
Merge a888033 into f965eab
Browse files Browse the repository at this point in the history
  • Loading branch information
dominichamon committed Jul 24, 2018
2 parents f965eab + a888033 commit 23b9e70
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
30 changes: 14 additions & 16 deletions include/benchmark/benchmark.h
Expand Up @@ -56,8 +56,7 @@ static void BM_memcpy(benchmark::State& state) {
memset(src, 'x', state.range(0));
for (auto _ : state)
memcpy(dst, src, state.range(0));
state.SetBytesProcessed(int64_t(state.iterations()) *
int64_t(state.range(0)));
state.SetBytesProcessed(state.iterations() * state.range(0));
delete[] src; delete[] dst;
}
BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1<<10)->Arg(8<<10);
Expand Down Expand Up @@ -122,8 +121,7 @@ template <class Q> int BM_Sequential(benchmark::State& state) {
q.Wait(&v);
}
// actually messages, not bytes:
state.SetBytesProcessed(
static_cast<int64_t>(state.iterations())*state.range(0));
state.SetBytesProcessed(state.iterations() * state.range(0));
}
BENCHMARK_TEMPLATE(BM_Sequential, WaitQueue<int>)->Range(1<<0, 1<<10);
Expand Down Expand Up @@ -454,7 +452,7 @@ class State {
// while (state.KeepRunningBatch(1000)) {
// // process 1000 elements
// }
bool KeepRunningBatch(size_t n);
bool KeepRunningBatch(int64_t n);

// REQUIRES: timer is running and 'SkipWithError(...)' has not been called
// by the current thread.
Expand Down Expand Up @@ -581,7 +579,7 @@ class State {
int64_t range_y() const { return range(1); }

BENCHMARK_ALWAYS_INLINE
size_t iterations() const {
int64_t iterations() const {
if (BENCHMARK_BUILTIN_EXPECT(!started_, false)) {
return 0;
}
Expand All @@ -592,15 +590,15 @@ class State {
: // items we expect on the first cache line (ie 64 bytes of the struct)
// When total_iterations_ is 0, KeepRunning() and friends will return false.
// May be larger than max_iterations.
size_t total_iterations_;
int64_t total_iterations_;

// When using KeepRunningBatch(), batch_leftover_ holds the number of
// iterations beyond max_iters that were run. Used to track
// completed_iterations_ accurately.
size_t batch_leftover_;
int64_t batch_leftover_;

public:
const size_t max_iterations;
const int64_t max_iterations;

private:
bool started_;
Expand All @@ -624,15 +622,15 @@ class State {
const int threads;

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

private:
void StartKeepRunning();
// Implementation of KeepRunning() and KeepRunningBatch().
// is_batch must be true unless n is 1.
bool KeepRunningInternal(size_t n, bool is_batch);
bool KeepRunningInternal(int64_t n, bool is_batch);
void FinishKeepRunning();
internal::ThreadTimer* timer_;
internal::ThreadManager* manager_;
Expand All @@ -643,11 +641,11 @@ inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunning() {
return KeepRunningInternal(1, /*is_batch=*/false);
}

inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningBatch(size_t n) {
inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningBatch(int64_t n) {
return KeepRunningInternal(n, /*is_batch=*/true);
}

inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningInternal(size_t n,
inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningInternal(int64_t n,
bool is_batch) {
// total_iterations_ is set to 0 by the constructor, and always set to a
// nonzero value by StartKepRunning().
Expand Down Expand Up @@ -711,7 +709,7 @@ struct State::StateIterator {
}

private:
size_t cached_;
int64_t cached_;
State* const parent_;
};

Expand Down Expand Up @@ -815,7 +813,7 @@ class Benchmark {
// NOTE: This function should only be used when *exact* iteration control is
// needed and never to control or limit how long a benchmark runs, where
// `--benchmark_min_time=N` or `MinTime(...)` should be used instead.
Benchmark* Iterations(size_t n);
Benchmark* Iterations(int64_t n);

// Specify the amount of times to repeat this benchmark. This option overrides
// the `benchmark_repetitions` flag.
Expand Down Expand Up @@ -906,7 +904,7 @@ class Benchmark {
TimeUnit time_unit_;
int range_multiplier_;
double min_time_;
size_t iterations_;
int64_t iterations_;
int repetitions_;
bool use_real_time_;
bool use_manual_time_;
Expand Down
10 changes: 5 additions & 5 deletions src/benchmark.cc
Expand Up @@ -104,7 +104,7 @@ DEFINE_int32(v, 0, "The level of verbose logging to output");
namespace benchmark {

namespace {
static const size_t kMaxIterations = 1000000000;
static const int64_t kMaxIterations = 1000000000;

static MemoryManager* memory_manager = nullptr;
} // end namespace
Expand Down Expand Up @@ -171,7 +171,7 @@ BenchmarkReporter::Run CreateRunReport(
// Execute one thread of benchmark b for the specified number of iterations.
// Adds the stats collected for the thread into *total.
void RunInThread(const benchmark::internal::Benchmark::Instance* b,
size_t iters, int thread_id,
int64_t iters, int thread_id,
internal::ThreadManager* manager) {
internal::ThreadTimer timer;
State st(iters, b->arg, thread_id, b->threads, &timer, manager);
Expand Down Expand Up @@ -199,7 +199,7 @@ std::vector<BenchmarkReporter::Run> RunBenchmark(
std::vector<BenchmarkReporter::Run> reports; // return value

const bool has_explicit_iteration_count = b.iterations != 0;
size_t iters = has_explicit_iteration_count ? b.iterations : 1;
int64_t iters = has_explicit_iteration_count ? b.iterations : 1;
std::unique_ptr<internal::ThreadManager> manager;
std::vector<std::thread> pool(b.threads - 1);
const int repeats =
Expand Down Expand Up @@ -321,8 +321,8 @@ std::vector<BenchmarkReporter::Run> RunBenchmark(
} // namespace
} // namespace internal

State::State(size_t max_iters, const std::vector<int64_t>& ranges, int thread_i,
int n_threads, internal::ThreadTimer* timer,
State::State(int64_t max_iters, const std::vector<int64_t>& ranges,
int thread_i, int n_threads, internal::ThreadTimer* timer,
internal::ThreadManager* manager)
: total_iterations_(0),
batch_leftover_(0),
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark_register.cc
Expand Up @@ -355,7 +355,7 @@ Benchmark* Benchmark::MinTime(double t) {
return this;
}

Benchmark* Benchmark::Iterations(size_t n) {
Benchmark* Benchmark::Iterations(int64_t n) {
CHECK(n > 0);
CHECK(IsZero(min_time_));
iterations_ = n;
Expand Down
8 changes: 4 additions & 4 deletions test/basic_test.cc
Expand Up @@ -98,7 +98,7 @@ BENCHMARK(BM_empty_stop_start)->ThreadPerCpu();


void BM_KeepRunning(benchmark::State& state) {
size_t iter_count = 0;
int64_t iter_count = 0;
assert(iter_count == state.iterations());
while (state.KeepRunning()) {
++iter_count;
Expand All @@ -109,8 +109,8 @@ BENCHMARK(BM_KeepRunning);

void BM_KeepRunningBatch(benchmark::State& state) {
// Choose a prime batch size to avoid evenly dividing max_iterations.
const size_t batch_size = 101;
size_t iter_count = 0;
const int64_t batch_size = 101;
int64_t iter_count = 0;
while (state.KeepRunningBatch(batch_size)) {
iter_count += batch_size;
}
Expand All @@ -119,7 +119,7 @@ void BM_KeepRunningBatch(benchmark::State& state) {
BENCHMARK(BM_KeepRunningBatch);

void BM_RangedFor(benchmark::State& state) {
size_t iter_count = 0;
int64_t iter_count = 0;
for (auto _ : state) {
++iter_count;
}
Expand Down

0 comments on commit 23b9e70

Please sign in to comment.