Debian Codegraph @

src/jmh/java/io/reactivex/rxjava3/core/PublishProcessorPerf.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 import org.openjdk.jmh.infra.Blackhole;
20
21 import io.reactivex.rxjava3.processors.PublishProcessor;
22 import io.reactivex.rxjava3.subjects.PublishSubject;
23
24 @BenchmarkMode(Mode.Throughput)
25 @Warmup(iterations = 5)
26 @Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)
27 @OutputTimeUnit(TimeUnit.SECONDS)
28 @Fork(value = 1)
29 @State(Scope.Thread)
30 public class PublishProcessorPerf {
31
32 PublishProcessor<Integer> unbounded;
33
34 PublishProcessor<Integer> bounded;
35
36 PublishSubject<Integer> subject;
37
38 @Setup
39 public void setup(Blackhole bh) {
40 unbounded = PublishProcessor.create();
41 unbounded.subscribe(new PerfConsumer(bh));
42
43 bounded = PublishProcessor.create();
44 bounded.subscribe(new PerfBoundedSubscriber(bh, 1000 * 1000));
45
46 subject = PublishSubject.create();
47 subject.subscribe(new PerfConsumer(bh));
48 }
49
50 @Benchmark
51 public void unbounded1() {
52 unbounded.onNext(1);
53 }
54
55 @Benchmark
56 public void unbounded1k() {
57 for (int i = 0; i < 1000; i++) {
58 unbounded.onNext(1);
59 }
60 }
61
62 @Benchmark
63 public void unbounded1m() {
64 for (int i = 0; i < 1000000; i++) {
65 unbounded.onNext(1);
66 }
67 }
68
69 @Benchmark
70 public void bounded1() {
71 bounded.onNext(1);
72 }
73
74 @Benchmark
75 public void bounded1k() {
76 for (int i = 0; i < 1000; i++) {
77 bounded.onNext(1);
78 }
79 }
80
81 @Benchmark
82 public void bounded1m() {
83 for (int i = 0; i < 1000000; i++) {
84 bounded.onNext(1);
85 }
86 }
87
88 @Benchmark
89 public void subject1() {
90 subject.onNext(1);
91 }
92
93 @Benchmark
94 public void subject1k() {
95 for (int i = 0; i < 1000; i++) {
96 subject.onNext(1);
97 }
98 }
99
100 @Benchmark
101 public void subject1m() {
102 for (int i = 0; i < 1000000; i++) {
103 subject.onNext(1);
104 }
105 }
106 }