1plugins { 2 id 'me.champeau.gradle.jmh' version '0.4.8' 3} 4 5apply plugin: 'idea' 6 7description = 'Conscrypt: JMH on OpenJDK Benchmarks' 8 9evaluationDependsOn(':conscrypt-openjdk') 10 11ext { 12 preferredSourceSet = project(':conscrypt-openjdk').preferredSourceSet 13 preferredNativeFileDir = project(':conscrypt-openjdk').preferredNativeFileDir 14 15 genDir = "${buildDir}/jmh-generated-classes" 16 jmhInclude = System.getProperty('jmh.include') 17 jmhParams = System.getProperty('jmh.parameters') 18 jmhWarmupIterations = System.getProperty('jmh.wi', '10') 19 jmhIterations = System.getProperty('jmh.i', '10') 20 jmhFork = System.getProperty('jmh.f', '1') 21 jmhJvm = System.getProperty('jmh.jvm') 22 jmhJvmArgs = System.getProperty('jmh.jvmArgs', '-server -Xms2g -Xmx2g') 23} 24 25// We're not distributing this, so it's safe to use newer language features. 26sourceCompatibility = JavaVersion.VERSION_1_8 27targetCompatibility = JavaVersion.VERSION_1_8 28 29jmh { 30 jmhVersion = "$jmhVersion" 31 if (jmhInclude != null) { 32 setInclude(jmhInclude.toString()) 33 } 34 if (jmhParams != null) { 35 setBenchmarkParameters(parseParams(jmhParams)) 36 } 37 warmupIterations = "$jmhWarmupIterations".toInteger() 38 iterations = "$jmhIterations".toInteger(); 39 fork = "$jmhFork".toInteger() 40 jvmArgs = jmhJvmArgs.toString() 41 if (jmhJvm != null) { 42 jvm = jmhJvm 43 } 44 duplicateClassesStrategy = 'warn' 45} 46 47configurations { 48 // The JMH plugin by defaults depends on all of the generators for an old version of JMH. 49 // Need to remove all the generators that we're not explicitly overriding to eliminate the 50 // dependency on the old version of JMH. 51 jmh.exclude module:'jmh-generator-asm' 52 53 jmhGeneratorAnnprocess 54} 55 56sourceSets { 57 sourceSets { 58 main { 59 resources { 60 // This shouldn't be needed but seems to help IntelliJ locate 61 // META_INF/BenchmarkList. 62 srcDirs += genDir 63 64 // This shouldn't be needed but seems to help IntelliJ locate the native artifact. 65 srcDirs += preferredNativeFileDir 66 } 67 } 68 } 69} 70 71dependencies { 72 compile project(path: ":conscrypt-openjdk", configuration: "runtime"), 73 project(':conscrypt-benchmark-base'), 74 // Add the preferred native openjdk configuration for this platform. 75 project(':conscrypt-openjdk').sourceSets["$preferredSourceSet"].output, 76 libraries.junit, 77 libraries.netty_handler, 78 libraries.netty_tcnative 79 80 jmhGeneratorAnnprocess libraries.jmh_generator_annprocess 81 82 // Override the default JMH dependencies with the new versions. 83 jmh libraries.jmh_core, 84 libraries.jmh_generator_reflection, 85 libraries.jmh_generator_bytecode 86} 87 88// Running benchmarks in IntelliJ seems broken without this. 89// See https://github.com/melix/jmh-gradle-plugin/issues/39 90idea.module { 91 scopes.PROVIDED.plus += [ configurations.compile, configurations.jmh ] 92} 93 94// Param strings are in the form "param:VAL1,VAL2;param2:VAL3,VAL4" 95def parseParams(s) { 96 // It's really easy to type jmh.parameters=foo=bar instead of jmh.parameters=foo:bar, 97 // so check for that. 98 if (s.contains("=")) { 99 throw new IllegalArgumentException("jmh.parameters value shouldn't include '='. (Did you mean ':'?)") 100 } 101 return s.split(";").collectEntries { entry -> 102 def pair = entry.split(":") 103 [ (pair.first().trim()) : pair.last().split(",").collect { it.trim() } ] 104 } 105} 106