Skip to content

Commit 479df31

Browse files
authored
1.x: PublishSubject perf (#4224)
* 1.x: PublishSubject perf * Update year.
1 parent a45de22 commit 479df31

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2016 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.subjects;
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.jmh.LatchedObserver;
25+
26+
/**
27+
* Benchmark PublishSubject.
28+
* <p>
29+
* gradlew benchmarks "-Pjmh=-f 1 -tu s -bm thrpt -wi 5 -i 5 -r 1 .*PublishSubjectPerf.*"
30+
* <p>
31+
* gradlew benchmarks "-Pjmh=-f 1 -tu ns -bm avgt -wi 5 -i 5 -r 1 .*PublishSubjectPerf.*"
32+
*/
33+
@BenchmarkMode(Mode.Throughput)
34+
@OutputTimeUnit(TimeUnit.SECONDS)
35+
@State(Scope.Thread)
36+
public class PublishSubjectPerf {
37+
38+
@Param({ "1", "2", "4", "8"})
39+
public int subscribers;
40+
41+
@Param({ "1", "1000", "1000000"})
42+
public int count;
43+
44+
@Benchmark
45+
public Object benchmark(Blackhole bh) {
46+
PublishSubject<Integer> ps = PublishSubject.create();
47+
48+
int s = subscribers;
49+
for (int i = 0; i < s; i++) {
50+
ps.subscribe(new LatchedObserver<Integer>(bh));
51+
}
52+
53+
int c = count;
54+
for (int i = 0; i < c; i++) {
55+
ps.onNext(777);
56+
}
57+
58+
ps.onCompleted();
59+
60+
return ps;
61+
}
62+
}

0 commit comments

Comments
 (0)