Debian Codegraph @

src/jmh/java/io/reactivex/rxjava3/core/BlockingGetPerf.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. 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 distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.core;
15
16 import java.util.concurrent.TimeUnit;
17
18 import org.openjdk.jmh.annotations.*;
19
20 @BenchmarkMode(Mode.Throughput)
21 @Warmup(iterations = 5)
22 @Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)
23 @OutputTimeUnit(TimeUnit.SECONDS)
24 @Fork(value = 1)
25 @State(Scope.Thread)
26 public class BlockingGetPerf {
27 Flowable<Integer> flowable;
28
29 Observable<Integer> observable;
30
31 Single<Integer> single;
32
33 Maybe<Integer> maybe;
34
35 Completable completable;
36
37 @Setup
38 public void setup() {
39 flowable = Flowable.just(1);
40
41 observable = Observable.just(1);
42
43 single = Single.just(1);
44
45 maybe = Maybe.just(1);
46
47 completable = Completable.complete();
48 }
49
50 @Benchmark
51 public Object flowableBlockingFirst() {
52 return flowable.blockingFirst();
53 }
54
55 @Benchmark
56 public Object flowableBlockingLast() {
57 return flowable.blockingLast();
58 }
59
60 @Benchmark
61 public Object observableBlockingLast() {
62 return observable.blockingLast();
63 }
64
65 @Benchmark
66 public Object observableBlockingFirst() {
67 return observable.blockingFirst();
68 }
69
70 @Benchmark
71 public Object single() {
72 return single.blockingGet();
73 }
74
75 @Benchmark
76 public Object maybe() {
77 return maybe.blockingGet();
78 }
79
80 @Benchmark
81 public void completable() {
82 completable.blockingAwait();
83 }
84 }