Debian Codegraph @

src/jmh/java/io/reactivex/rxjava3/core/FlowableFlatMapCompletableSyncPerf.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 import org.openjdk.jmh.infra.Blackhole;
21
22 import io.reactivex.rxjava3.internal.functions.Functions;
23
24 @BenchmarkMode(Mode.Throughput)
25 @Warmup(iterations = 5)
26 @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
27 @OutputTimeUnit(TimeUnit.SECONDS)
28 @Fork(value = 1)
29 @State(Scope.Thread)
30 public class FlowableFlatMapCompletableSyncPerf {
31
32 @Param({"1", "10", "100", "1000", "10000", "100000", "1000000"})
33 int items;
34
35 @Param({"1", "8", "32", "128", "256"})
36 int maxConcurrency;
37
38 Completable flatMapCompletable;
39
40 Flowable<Object> flatMap;
41
42 @Setup
43 public void setup() {
44 Integer[] array = new Integer[items];
45 Arrays.fill(array, 777);
46
47 flatMapCompletable = Flowable.fromArray(array)
48 .flatMapCompletable(Functions.justFunction(Completable.complete()), false, maxConcurrency);
49
50 flatMap = Flowable.fromArray(array)
51 .flatMap(Functions.justFunction(Completable.complete().toFlowable()), false, maxConcurrency);
52 }
53
54 @Benchmark
55 public Object flatMap(Blackhole bh) {
56 return flatMap.subscribeWith(new PerfConsumer(bh));
57 }
58
59 @Benchmark
60 public Object flatMapCompletable(Blackhole bh) {
61 return flatMapCompletable.subscribeWith(new PerfConsumer(bh));
62 }
63 }