-
Notifications
You must be signed in to change notification settings - Fork 1
/
ServiceProviderBenchmark.java
62 lines (50 loc) · 1.44 KB
/
ServiceProviderBenchmark.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
package io.github.amayaframework.di;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup
public class ServiceProviderBenchmark {
private static final ServiceProvider PROVIDER = ProviderBuilders
.createChecked()
.addTransient(Service1.class)
.addTransient(Service2.class)
.addTransient(Service3.class)
.addTransient(App.class)
.build();
@Benchmark
public void benchManualInjection(Blackhole blackhole) {
var app = new App(new Service1());
app.s2 = new Service2();
app.setS3(new Service3(new Service1()));
blackhole.consume(app);
}
@Benchmark
public void benchAmayaInjection(Blackhole blackhole) {
blackhole.consume(PROVIDER.get(App.class));
}
public static final class Service1 {
}
public static final class Service2 {
}
public static final class Service3 {
final Service1 s1;
public Service3(Service1 s1) {
this.s1 = s1;
}
}
public static final class App {
final Service1 s1;
@Inject
public Service2 s2;
Service3 s3;
public App(Service1 s1) {
this.s1 = s1;
}
@Inject
public void setS3(Service3 s3) {
this.s3 = s3;
}
}
}