blob: 613ffdee2b71a1b0318bcb8b3bf507ea7554adde [file] [log] [blame]
Ben Clayton55890e12020-01-31 14:07:21 +00001// Copyright 2020 The SwiftShader Authors. All Rights Reserved.
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// http://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 "Coroutine.hpp"
16#include "Reactor.hpp"
17
18#include "benchmark/benchmark.h"
19
20BENCHMARK_MAIN();
21
22class Coroutines : public benchmark::Fixture
23{
24public:
25 void SetUp(const ::benchmark::State &state) {}
26
27 void TearDown(const ::benchmark::State &state) {}
28};
29
30BENCHMARK_F(Coroutines, Fibonacci)
31(benchmark::State &state)
32{
33 using namespace rr;
34
35 if(!Caps.CoroutinesSupported)
36 {
37 state.SkipWithError("Coroutines are not supported");
38 return;
39 }
40
41 Coroutine<int()> function;
42 {
43 Yield(Int(0));
44 Yield(Int(1));
45 Int current = 1;
46 Int next = 1;
47 While(true)
48 {
49 Yield(next);
50 auto tmp = current + next;
51 current = next;
52 next = tmp;
53 }
54 }
55
56 auto coroutine = function();
57
58 int out = 0;
59 for(auto _ : state)
60 {
61 coroutine->await(out);
62 }
63}