Debian Codegraph @

src/jmh/java/io/reactivex/rxjava3/core/BlockingPerf.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.Arrays;
17 import java.util.concurrent.TimeUnit;
18
19 import org.openjdk.jmh.annotations.*;
20
21 @BenchmarkMode(Mode.Throughput)
22 @Warmup(iterations = 5)
23 @Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)
24 @OutputTimeUnit(TimeUnit.SECONDS)
25 @Fork(value = 1)
26 @State(Scope.Thread)
27 public class BlockingPerf {
28 @Param({ "1", "1000", "1000000" })
29 public int times;
30
31 Flowable<Integer> flowable;
32
33 Observable<Integer> observable;
34
35 @Setup
36 public void setup() {
37 Integer[] array = new Integer[times];
38 Arrays.fill(array, 777);
39
40 flowable = Flowable.fromArray(array);
41
42 observable = Observable.fromArray(array);
43 }
44
45 @Benchmark
46 public Object flowableBlockingFirst() {
47 return flowable.blockingFirst();
48 }
49
50 @Benchmark
51 public Object flowableBlockingLast() {
52 return flowable.blockingLast();
53 }
54
55 @Benchmark
56 public Object observableBlockingLast() {
57 return observable.blockingLast();
58 }
59
60 @Benchmark
61 public Object observableBlockingFirst() {
62 return observable.blockingFirst();
63 }
64 }