Skip to content

Commit 78572f3

Browse files
Update Perf Tests
matching with work being done for 0.20 to allow comparisons
1 parent 37ccadb commit 78572f3

File tree

3 files changed

+80
-17
lines changed

3 files changed

+80
-17
lines changed

rxjava-core/src/perf/java/rx/PerfBaseline.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ public void observableConsumption(Input input) throws InterruptedException {
3939
public void observableViaRange(Input input) throws InterruptedException {
4040
input.observable.subscribe(input.observer);
4141
}
42+
43+
@Benchmark
44+
public void observableConsumptionUnsafe(Input input) throws InterruptedException {
45+
input.firehose.unsafeSubscribe(input.newSubscriber());
46+
}
47+
48+
@Benchmark
49+
public void observableViaRangeUnsafe(Input input) throws InterruptedException {
50+
input.observable.unsafeSubscribe(input.newSubscriber());
51+
}
4252

4353
@Benchmark
4454
public void iterableViaForLoopConsumption(Input input) throws InterruptedException {

rxjava-core/src/perf/java/rx/jmh/InputWithIncrementingInteger.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public abstract class InputWithIncrementingInteger {
3232
public Iterable<Integer> iterable;
3333
public Observable<Integer> observable;
3434
public Observable<Integer> firehose;
35-
private Blackhole bh;
35+
public Blackhole bh;
3636
public Observer<Integer> observer;
3737

3838
public abstract int getSize();
39-
39+
4040
@Setup
4141
public void setup(final Blackhole bh) {
4242
this.bh = bh;
@@ -106,4 +106,25 @@ public LatchedObserver<Integer> newLatchedObserver() {
106106
return new LatchedObserver<Integer>(bh);
107107
}
108108

109+
public Subscriber<Integer> newSubscriber() {
110+
return new Subscriber<Integer>() {
111+
112+
@Override
113+
public void onCompleted() {
114+
115+
}
116+
117+
@Override
118+
public void onError(Throwable e) {
119+
120+
}
121+
122+
@Override
123+
public void onNext(Integer t) {
124+
bh.consume(t);
125+
}
126+
127+
};
128+
}
129+
109130
}

rxjava-core/src/perf/java/rx/operators/OperatorMergePerf.java

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.util.List;
2020
import java.util.concurrent.TimeUnit;
2121

22-
import org.openjdk.jmh.annotations.BenchmarkMode;
2322
import org.openjdk.jmh.annotations.Benchmark;
23+
import org.openjdk.jmh.annotations.BenchmarkMode;
2424
import org.openjdk.jmh.annotations.Mode;
2525
import org.openjdk.jmh.annotations.OutputTimeUnit;
2626
import org.openjdk.jmh.annotations.Param;
@@ -39,21 +39,25 @@
3939
@OutputTimeUnit(TimeUnit.SECONDS)
4040
public class OperatorMergePerf {
4141

42-
@State(Scope.Thread)
43-
public static class Input extends InputWithIncrementingInteger {
44-
45-
@Param({ "1", "1000" })
46-
public int size;
42+
// flatMap
43+
@Benchmark
44+
public void oneStreamOfNthatMergesIn1(final InputMillion input) throws InterruptedException {
45+
Observable<Observable<Integer>> os = Observable.range(1, input.size).map(new Func1<Integer, Observable<Integer>>() {
4746

48-
@Override
49-
public int getSize() {
50-
return size;
51-
}
47+
@Override
48+
public Observable<Integer> call(Integer i) {
49+
return Observable.just(i);
50+
}
5251

52+
});
53+
LatchedObserver<Integer> o = input.newLatchedObserver();
54+
Observable.merge(os).subscribe(o);
55+
o.latch.await();
5356
}
5457

58+
// flatMap
5559
@Benchmark
56-
public void merge1SyncStreamOfN(final Input input) throws InterruptedException {
60+
public void merge1SyncStreamOfN(final InputMillion input) throws InterruptedException {
5761
Observable<Observable<Integer>> os = Observable.just(1).map(new Func1<Integer, Observable<Integer>>() {
5862

5963
@Override
@@ -66,9 +70,9 @@ public Observable<Integer> call(Integer i) {
6670
Observable.merge(os).subscribe(o);
6771
o.latch.await();
6872
}
69-
73+
7074
@Benchmark
71-
public void mergeNSyncStreamsOfN(final Input input) throws InterruptedException {
75+
public void mergeNSyncStreamsOfN(final InputThousand input) throws InterruptedException {
7276
Observable<Observable<Integer>> os = input.observable.map(new Func1<Integer, Observable<Integer>>() {
7377

7478
@Override
@@ -83,7 +87,7 @@ public Observable<Integer> call(Integer i) {
8387
}
8488

8589
@Benchmark
86-
public void mergeNAsyncStreamsOfN(final Input input) throws InterruptedException {
90+
public void mergeNAsyncStreamsOfN(final InputThousand input) throws InterruptedException {
8791
Observable<Observable<Integer>> os = input.observable.map(new Func1<Integer, Observable<Integer>>() {
8892

8993
@Override
@@ -98,7 +102,7 @@ public Observable<Integer> call(Integer i) {
98102
}
99103

100104
@Benchmark
101-
public void mergeTwoAsyncStreamsOfN(final Input input) throws InterruptedException {
105+
public void mergeTwoAsyncStreamsOfN(final InputThousand input) throws InterruptedException {
102106
LatchedObserver<Integer> o = input.newLatchedObserver();
103107
Observable<Integer> ob = Observable.range(0, input.size).subscribeOn(Schedulers.computation());
104108
Observable.merge(ob, ob).subscribe(o);
@@ -115,6 +119,7 @@ public void mergeNSyncStreamsOf1(final InputForMergeN input) throws InterruptedE
115119
@State(Scope.Thread)
116120
public static class InputForMergeN {
117121
@Param({ "1", "100", "1000" })
122+
// @Param({ "1000" })
118123
public int size;
119124

120125
private Blackhole bh;
@@ -134,4 +139,31 @@ public LatchedObserver<Integer> newLatchedObserver() {
134139
}
135140
}
136141

142+
@State(Scope.Thread)
143+
public static class InputMillion extends InputWithIncrementingInteger {
144+
145+
@Param({ "1", "1000", "1000000" })
146+
// @Param({ "1000" })
147+
public int size;
148+
149+
@Override
150+
public int getSize() {
151+
return size;
152+
}
153+
154+
}
155+
156+
@State(Scope.Thread)
157+
public static class InputThousand extends InputWithIncrementingInteger {
158+
159+
@Param({ "1", "1000" })
160+
// @Param({ "1000" })
161+
public int size;
162+
163+
@Override
164+
public int getSize() {
165+
return size;
166+
}
167+
168+
}
137169
}

0 commit comments

Comments
 (0)