blob: ab25b2fc103a61b4797a96300a3aaf5b115b5b7e (
plain)
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
|
plugins {
id 'java-library'
id 'me.champeau.jmh'
}
configurations {
// create a configuration for the sources and dependencies of each benchmark
caffeineSources
caffeineDeps
autodisposeSources
autodisposeDeps
}
dependencies {
// Add NullAway and Error Prone Core as dependencies. This ensures that the classes get included
// in the jmh-generated jar, and hence get JIT-compiled during benchmarking. Without this dependence, NullAway
// can still be loaded via the processor path, but it gets reloaded on each run of compilation, skewing
// performance measurements
implementation project(':nullaway')
// use the same version of Error Prone Core that we are compiling NullAway against, so we can
// benchmark against different versions of Error Prone
implementation deps.build.errorProneCoreForApi
// Source jars for our desired benchmarks
caffeineSources('com.github.ben-manes.caffeine:caffeine:3.0.2:sources') {
transitive = false
}
autodisposeSources('com.uber.autodispose2:autodispose:2.1.0:sources') {
transitive = false
}
caffeineDeps 'com.github.ben-manes.caffeine:caffeine:3.0.2'
autodisposeDeps 'com.uber.autodispose2:autodispose:2.1.0'
testImplementation deps.test.junit4
}
def caffeineSourceDir = project.layout.buildDirectory.dir('caffeineSources')
def autodisposeSourceDir = project.layout.buildDirectory.dir('autodisposeSources')
task extractCaffeineSources(type: Copy) {
from zipTree(configurations.caffeineSources.singleFile)
into caffeineSourceDir
}
task extractAutodisposeSources(type: Copy) {
from zipTree(configurations.autodisposeSources.singleFile)
into autodisposeSourceDir
}
compileJava.dependsOn(extractCaffeineSources)
compileJava.dependsOn(extractAutodisposeSources)
// always run jmh
tasks.getByName('jmh').outputs.upToDateWhen { false }
jmh {
// seems we need more iterations to fully warm up the JIT
warmupIterations = 10
// a trick: to get the classpath for a benchmark, create a configuration that depends on the benchmark, and
// then filter out the benchmark itself
def caffeineClasspath = configurations.caffeineDeps.filter({f -> !f.toString().contains("caffeine-3.0.2")}).asPath
def autodisposeClasspath = configurations.autodisposeDeps.filter({f -> !f.toString().contains("autodispose-2.1.0")}).asPath
jvmArgsAppend = [
"-Dnullaway.caffeine.sources=${caffeineSourceDir.get()}",
"-Dnullaway.caffeine.classpath=$caffeineClasspath",
"-Dnullaway.autodispose.sources=${autodisposeSourceDir.get()}",
"-Dnullaway.autodispose.classpath=$autodisposeClasspath",
]
// commented-out examples of how to tweak other jmh parameters; they show the default values
// for more examples see https://github.com/melix/jmh-gradle-plugin/blob/master/README.adoc#configuration-options
// iterations = 5
// fork = 5
}
// don't run test task on pre-JDK-11 VMs
test.onlyIf { JavaVersion.current() >= JavaVersion.VERSION_11 }
|