1 // Copyright 2020 The Marl Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "marl_bench.h"
16
17 #include "marl/waitgroup.h"
18
19 #include "benchmark/benchmark.h"
20
BENCHMARK_DEFINE_F(Schedule,Empty)21 BENCHMARK_DEFINE_F(Schedule, Empty)(benchmark::State& state) {
22 run(state, [&](int numTasks) {
23 for (auto _ : state) {
24 for (auto i = 0; i < numTasks; i++) {
25 marl::schedule([] {});
26 }
27 }
28 });
29 }
30 BENCHMARK_REGISTER_F(Schedule, Empty)->Apply(Schedule::args);
31
BENCHMARK_DEFINE_F(Schedule,SomeWork)32 BENCHMARK_DEFINE_F(Schedule, SomeWork)
33 (benchmark::State& state) {
34 run(state, [&](int numTasks) {
35 for (auto _ : state) {
36 marl::WaitGroup wg;
37 wg.add(numTasks);
38 for (auto i = 0; i < numTasks; i++) {
39 marl::schedule([=] {
40 uint32_t value = doSomeWork(i);
41 benchmark::DoNotOptimize(value);
42 wg.done();
43 });
44 }
45 wg.wait();
46 }
47 });
48 }
49 BENCHMARK_REGISTER_F(Schedule, SomeWork)->Apply(Schedule::args);
50
BENCHMARK_DEFINE_F(Schedule,SomeWorkWorkerAffinityOneOf)51 BENCHMARK_DEFINE_F(Schedule, SomeWorkWorkerAffinityOneOf)
52 (benchmark::State& state) {
53 marl::Scheduler::Config cfg;
54 cfg.setWorkerThreadAffinityPolicy(
55 marl::Thread::Affinity::Policy::oneOf(marl::Thread::Affinity::all()));
56 run(state, cfg, [&](int numTasks) {
57 for (auto _ : state) {
58 marl::WaitGroup wg;
59 wg.add(numTasks);
60 for (auto i = 0; i < numTasks; i++) {
61 marl::schedule([=] {
62 uint32_t value = doSomeWork(i);
63 benchmark::DoNotOptimize(value);
64 wg.done();
65 });
66 }
67 wg.wait();
68 }
69 });
70 }
71 BENCHMARK_REGISTER_F(Schedule, SomeWorkWorkerAffinityOneOf)
72 ->Apply(Schedule::args);
73