Debian Codegraph @

src/jmh/java/io/reactivex/rxjava3/core/FlowableFlatMapCompletableAsyncPerf.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.functions.Action;
23 import io.reactivex.rxjava3.internal.functions.Functions;
24 import io.reactivex.rxjava3.schedulers.Schedulers;
25
26 @BenchmarkMode(Mode.Throughput)
27 @Warmup(iterations = 5)
28 @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
29 @OutputTimeUnit(TimeUnit.SECONDS)
30 @Fork(value = 1)
31 @State(Scope.Thread)
32 public class FlowableFlatMapCompletableAsyncPerf implements Action {
33
34 @Param({"1", "10", "100", "1000", "10000", "100000", "1000000"})
35 int items;
36
37 @Param({"1", "8", "32", "128", "256"})
38 int maxConcurrency;
39
40 @Param({"1", "10", "100", "1000"})
41 int work;
42
43 Completable flatMapCompletable;
44
45 Flowable<Object> flatMap;
46
47 @Override
48 public void run() {
49 Blackhole.consumeCPU(work);
50 }
51
52 @Setup
53 public void setup() {
54 Integer[] array = new Integer[items];
55 Arrays.fill(array, 777);
56
57 flatMapCompletable = Flowable.fromArray(array)
58 .flatMapCompletable(Functions.justFunction(Completable.fromAction(this).subscribeOn(Schedulers.computation())), false, maxConcurrency);
59
60 flatMap = Flowable.fromArray(array)
61 .flatMap(Functions.justFunction(Completable.fromAction(this).subscribeOn(Schedulers.computation()).toFlowable()), false, maxConcurrency);
62 }
63
64 // @Benchmark
65 public Object flatMap(Blackhole bh) {
66 return flatMap.subscribeWith(new PerfAsyncConsumer(bh)).await(items);
67 }
68
69 @Benchmark
70 public Object flatMapCompletable(Blackhole bh) {
71 return flatMapCompletable.subscribeWith(new PerfAsyncConsumer(bh)).await(items);
72 }
73 }