Skip to content

Commit ca7f862

Browse files
committed
Merge pull request #3475 from akarnokd/FlatMapRangePerf1x
1.x: benchmark range + flatMap throughput.
2 parents 92fe02d + 4b07cd3 commit ca7f862

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright 2014 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package rx.operators;
18+
19+
import java.util.concurrent.TimeUnit;
20+
21+
import org.openjdk.jmh.annotations.*;
22+
import org.openjdk.jmh.infra.Blackhole;
23+
24+
import rx.Observable;
25+
import rx.functions.Func1;
26+
import rx.jmh.LatchedObserver;
27+
28+
/**
29+
* Benchmark typical atomic operations on volatile fields and AtomicXYZ classes.
30+
* <p>
31+
* gradlew benchmarks "-Pjmh=-f 1 -tu s -bm thrpt -wi 5 -i 5 -r 1 .*FlatMapRangePerf.*"
32+
* <p>
33+
* gradlew benchmarks "-Pjmh=-f 1 -tu ns -bm avgt -wi 5 -i 5 -r 1 .*FlatMapRangePerf.*"
34+
*/
35+
@BenchmarkMode(Mode.Throughput)
36+
@OutputTimeUnit(TimeUnit.SECONDS)
37+
@State(Scope.Thread)
38+
public class FlatMapRangePerf {
39+
@Param({ "1", "10", "1000", "1000000" })
40+
public int times;
41+
42+
Observable<Integer> rangeFlatMapJust;
43+
Observable<Integer> rangeFlatMapRange;
44+
45+
@Setup
46+
public void setup() {
47+
Observable<Integer> range = Observable.range(1, times);
48+
49+
rangeFlatMapJust = range.flatMap(new Func1<Integer, Observable<Integer>>() {
50+
@Override
51+
public Observable<Integer> call(Integer v) {
52+
return Observable.just(v);
53+
}
54+
});
55+
rangeFlatMapRange = range.flatMap(new Func1<Integer, Observable<Integer>>() {
56+
@Override
57+
public Observable<Integer> call(Integer v) {
58+
return Observable.range(v, 2);
59+
}
60+
});
61+
}
62+
63+
@Benchmark
64+
public void rangeFlatMapJust(Blackhole bh) {
65+
rangeFlatMapJust.subscribe(new LatchedObserver<Object>(bh));
66+
}
67+
68+
@Benchmark
69+
public void rangeFlatMapRange(Blackhole bh) {
70+
rangeFlatMapRange.subscribe(new LatchedObserver<Object>(bh));
71+
}
72+
73+
}

0 commit comments

Comments
 (0)