Skip to content

Commit 4bc516c

Browse files
authored
2.x: Benchmark X-Map-Z operators (#5914)
1 parent 90bca55 commit 4bc516c

27 files changed

+2687
-1
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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;
15+
16+
import java.util.*;
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.functions.Function;
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 FlattenRangePerf {
31+
@Param({ "1", "10", "100", "1000", "10000", "100000", "1000000" })
32+
public int times;
33+
34+
Flowable<Integer> flowable;
35+
36+
Observable<Integer> observable;
37+
38+
@Setup
39+
public void setup() {
40+
Integer[] array = new Integer[times];
41+
Arrays.fill(array, 777);
42+
43+
final Iterable<Integer> list = Arrays.asList(1, 2);
44+
45+
flowable = Flowable.fromArray(array).flatMapIterable(new Function<Integer, Iterable<Integer>>() {
46+
@Override
47+
public Iterable<Integer> apply(Integer v) throws Exception {
48+
return list;
49+
}
50+
});
51+
52+
observable = Observable.fromArray(array).flatMapIterable(new Function<Integer, Iterable<Integer>>() {
53+
@Override
54+
public Iterable<Integer> apply(Integer v) throws Exception {
55+
return list;
56+
}
57+
});
58+
}
59+
60+
@Benchmark
61+
public void flowable(Blackhole bh) {
62+
flowable.subscribe(new PerfConsumer(bh));
63+
}
64+
65+
@Benchmark
66+
public void observable(Blackhole bh) {
67+
observable.subscribe(new PerfConsumer(bh));
68+
}
69+
}

src/jmh/java/io/reactivex/FlowableFlatMapCompletablePerf.java renamed to src/jmh/java/io/reactivex/FlowableFlatMapCompletableAsyncPerf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
@OutputTimeUnit(TimeUnit.SECONDS)
3030
@Fork(value = 1)
3131
@State(Scope.Thread)
32-
public class FlowableFlatMapCompletablePerf implements Action {
32+
public class FlowableFlatMapCompletableAsyncPerf implements Action {
3333

3434
@Param({"1", "10", "100", "1000", "10000", "100000", "1000000"})
3535
int items;

0 commit comments

Comments
 (0)