plugins {
    id 'me.champeau.jmh' version '0.7.2'
}

configurations {
    jmh
}

jmh {
    includes = ['pl\\.allegro\\.tech\\.hermes\\.benchmark\\..*']
    humanOutputFile = null
    jmhVersion = '1.36'
    zip64 = true
    verbosity = 'NORMAL'
    iterations = intProperty('jmh.iterations', 4)
    timeOnIteration = stringProperty('jmh.timeOnIteration', '80s')
    fork = intProperty('jmh.fork', 1)
    warmupIterations = intProperty('jmh.warmupIterations', 4)
    warmup = stringProperty('jmh.timeOnWarmupIteration', '80s')
    jvmArgs = listProperty('jmh.jvmArgs', ['-Xmx1g', '-Xms1g', '-XX:+UseG1GC'] + chronicleMapJvmArgs)
    failOnError = booleanProperty('jmh.failOnError', true)
    threads = intProperty('jmh.threads', 4)
    synchronizeIterations = false
    forceGC =  false
    duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE
}

dependencies {
    jmh group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.37'
    jmh group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.37'
    jmh group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.5'
    jmh project(':hermes-frontend')
    jmh project(':hermes-test-helper')
    jmh project(':hermes-common')
    jmh project(':hermes-tracker')
}

// Workaround for duplicated `BenchmarkList` and `CompilerHints` files from META-INF directory in jmh jar.
// Those duplications can prevent from running benchmark tests.
// More info https://github.com/melix/jmh-gradle-plugin/issues/6
tasks.getByName('jmhJar').doFirst() { duplicatesStrategy(DuplicatesStrategy.EXCLUDE) }
tasks.getByName('processJmhResources').doFirst() { duplicatesStrategy(DuplicatesStrategy.EXCLUDE) }

String stringProperty(String property, String defaultValue) {
    project.hasProperty(property) ? project.property(property) : defaultValue
}

List listProperty(String property, List defaultValue) {
    project.hasProperty(property) ? ((String) project.property(property)).split(' ').toList() : defaultValue
}

int intProperty(String property, int defaultValue) {
    project.hasProperty(property) ? Integer.valueOf(project.property(property)) : defaultValue
}

boolean booleanProperty(String property, boolean defaultValue) {
    project.hasProperty(property) ? Boolean.valueOf(project.property(property)) : defaultValue
}
