-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConcatArrayComparison.java
92 lines (75 loc) · 2.85 KB
/
ConcatArrayComparison.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package io.helidon.reactive.jmh.multi;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.Collection;
import java.util.concurrent.Flow;
import io.helidon.common.reactive.Multi;
public class ConcatArrayComparison {
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(ConcatArrayComparison.class.getSimpleName())
.warmupIterations(5)
.forks(2)
.build();
Collection<RunResult> results = new Runner(opt).run();
}
@SuppressWarnings("unchecked")
private static Flow.Publisher<Integer>[] createPubs() {
return new Flow.Publisher[] {
Multi.just(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
Multi.just(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
Multi.just(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
Multi.just(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
Multi.just(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
Multi.just(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3)};
}
@Benchmark
public void variableRequestsOldCA(Blackhole bh) {
new MultiConcatArrayOld<Integer>(createPubs())
.subscribe(new TestSubscriber(bh));
}
@Benchmark
public void reqMaxOldCA(Blackhole bh) {
new MultiConcatArrayOld<Integer>(createPubs())
.forEach(bh::consume);
}
@Benchmark
public void variableRequestsNewCA(Blackhole bh) {
new MultiConcatArrayNew<Integer>(createPubs())
.subscribe(new TestSubscriber(bh));
}
@Benchmark
public void reqMaxNewCA(Blackhole bh) {
new MultiConcatArrayNew<Integer>(createPubs())
.forEach(bh::consume);
}
static class TestSubscriber implements Flow.Subscriber<Integer> {
private Flow.Subscription subscription;
private Blackhole bh;
public TestSubscriber(final Blackhole bh) {
this.bh = bh;
}
@Override
public void onSubscribe(final Flow.Subscription subscription) {
this.subscription = subscription;
}
@Override
public void onNext(final Integer item) {
subscription.request(item);
bh.consume(item);
}
@Override
public void onError(final Throwable throwable) {
throwable.printStackTrace();
}
@Override
public void onComplete() {
bh.consume(2);
}
}
}