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/defer.h"
18 #include "marl/scheduler.h"
19 #include "marl/thread.h"
20 #include "marl/ticket.h"
21 
22 #include "benchmark/benchmark.h"
23 
BENCHMARK_DEFINE_F(Schedule,Ticket)24 BENCHMARK_DEFINE_F(Schedule, Ticket)(benchmark::State& state) {
25   run(state, [&](int numTasks) {
26     for (auto _ : state) {
27       marl::Ticket::Queue queue;
28       for (int i = 0; i < numTasks; i++) {
29         auto ticket = queue.take();
30         marl::schedule([ticket] {
31           ticket.wait();
32           ticket.done();
33         });
34       }
35       queue.take().wait();
36     }
37   });
38 }
39 BENCHMARK_REGISTER_F(Schedule, Ticket)->Apply(Schedule::args<512>);
40