19 #include <condition_variable>
22 #include <benchmark/benchmark.h>
43 std::lock_guard<std::mutex> l(
mu_);
49 std::unique_lock<std::mutex> l(
mu_);
58 std::condition_variable
cv_;
84 callback->counter_->DecrementCount();
96 template <
int kConcurrentFunctor>
98 const int num_iterations =
state.range(0);
101 const int num_add = num_iterations / kConcurrentFunctor;
103 while (
state.KeepRunningBatch(num_iterations)) {
105 for (
int i = 0;
i < kConcurrentFunctor; ++
i) {
119 ->RangePair(524288, 524288, 1, 1024);
121 ->RangePair(524288, 524288, 1, 1024);
123 ->RangePair(524288, 524288, 1, 1024);
125 ->RangePair(524288, 524288, 1, 1024);
127 ->RangePair(524288, 524288, 1, 1024);
129 ->RangePair(524288, 524288, 1, 1024);
144 callback->counter_->DecrementCount();
155 int thread_idx =
state.thread_index();
157 if (thread_idx == 0) {
161 const int num_iterations =
state.range(0) /
state.threads();
162 while (
state.KeepRunningBatch(num_iterations)) {
164 for (
int i = 0;
i < num_iterations; ++
i) {
171 if (thread_idx == 0) {
173 delete external_add_pool;
179 ->RangePair(524288, 524288, 1, 1024)
180 ->ThreadRange(1, 256);
201 callback->counter_->DecrementCount();
213 template <
int kConcurrentFunctor>
215 const int num_iterations =
state.range(0);
218 const int num_add = num_iterations / kConcurrentFunctor;
220 while (
state.KeepRunningBatch(num_iterations)) {
222 for (
int i = 0;
i < kConcurrentFunctor; ++
i) {
242 #if defined(__GNUC__) && !defined(SWIG)
243 #if defined(__i386__) || defined(__x86_64__)
244 #define CACHELINE_SIZE 64
245 #elif defined(__powerpc64__)
246 #define CACHELINE_SIZE 128
247 #elif defined(__aarch64__)
248 #define CACHELINE_SIZE 64
249 #elif defined(__arm__)
250 #if defined(__ARM_ARCH_5T__)
251 #define CACHELINE_SIZE 32
252 #elif defined(__ARM_ARCH_7A__)
253 #define CACHELINE_SIZE 64
256 #ifndef CACHELINE_SIZE
257 #define CACHELINE_SIZE 64
278 for (
int i = 0;
i < 1000; ++
i) {
281 callback->counter_->DecrementCount();
297 const int kNumSpikes = 1000;
299 std::vector<ShortWorkFunctorForAdd> work_vector(batch_size);
301 while (
state.KeepRunningBatch(kNumSpikes * batch_size)) {
302 for (
int i = 0;
i != kNumSpikes; ++
i) {
304 for (
auto& w : work_vector) {
311 state.SetItemsProcessed(
state.iterations() * batch_size);
324 int main(
int argc,
char* argv[]) {