| 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.xmapz; |
| 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 |
import org.reactivestreams.Publisher; |
| 22 |
|
| 23 |
import io.reactivex.rxjava3.core.*; |
| 24 |
import io.reactivex.rxjava3.functions.Function; |
| 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 FlowableConcatMapCompletablePerf { |
| 33 |
@Param({ "1", "10", "100", "1000", "10000", "100000", "1000000" }) |
| 34 |
public int count; |
| 35 |
|
| 36 |
Flowable<Integer> flowableConvert; |
| 37 |
|
| 38 |
Completable flowableDedicated; |
| 39 |
|
| 40 |
Flowable<Integer> flowablePlain; |
| 41 |
|
| 42 |
@Setup |
| 43 |
public void setup() { |
| 44 |
Integer[] sourceArray = new Integer[count]; |
| 45 |
Arrays.fill(sourceArray, 777); |
| 46 |
|
| 47 |
Flowable<Integer> source = Flowable.fromArray(sourceArray); |
| 48 |
|
| 49 |
flowablePlain = source.concatMap(new Function<Integer, Publisher<? extends Integer>>() { |
| 50 |
@Override |
| 51 |
public Publisher<? extends Integer> apply(Integer v) { |
| 52 |
return Flowable.empty(); |
| 53 |
} |
| 54 |
}); |
| 55 |
|
| 56 |
flowableConvert = source.concatMap(new Function<Integer, Publisher<? extends Integer>>() { |
| 57 |
@Override |
| 58 |
public Publisher<? extends Integer> apply(Integer v) { |
| 59 |
return Completable.complete().toFlowable(); |
| 60 |
} |
| 61 |
}); |
| 62 |
|
| 63 |
flowableDedicated = source.concatMapCompletable(new Function<Integer, Completable>() { |
| 64 |
@Override |
| 65 |
public Completable apply(Integer v) { |
| 66 |
return Completable.complete(); |
| 67 |
} |
| 68 |
}); |
| 69 |
} |
| 70 |
|
| 71 |
@Benchmark |
| 72 |
public Object flowablePlain(Blackhole bh) { |
| 73 |
return flowablePlain.subscribeWith(new PerfConsumer(bh)); |
| 74 |
} |
| 75 |
|
| 76 |
@Benchmark |
| 77 |
public Object flowableConvert(Blackhole bh) { |
| 78 |
return flowableConvert.subscribeWith(new PerfConsumer(bh)); |
| 79 |
} |
| 80 |
|
| 81 |
@Benchmark |
| 82 |
public Object flowableDedicated(Blackhole bh) { |
| 83 |
return flowableDedicated.subscribeWith(new PerfConsumer(bh)); |
| 84 |
} |
| 85 |
} |