This is probably more a Gradle question than a Caliper question, but I am still rather new to Gradle. I am interested in providing a task in my build that can run some benchmarks using Caliper. I have already added Caliper to my testCompile dependencies, and that works and pulls everything down. I would like to know how to provide a task that will actually run the benchmarks.
Btw, I already know about caliper-ci. I do have a Jenkins build, but it's on a cloud service that doesn't yet allow me to configure usage of caliper-ci, and besides, I want to be able to run locally before committing changes to the cloud.
Gradle determines the subset of the tasks, created and configured during the configuration phase, to be executed. The subset is determined by the task name arguments passed to the gradle command and the current directory. Gradle then executes each of the selected tasks.
By default, Gradle will run all tests that it detects, which it does by inspecting the compiled test classes. This detection uses different criteria depending on the test framework used. For JUnit, Gradle scans for both JUnit 3 and 4 test classes.
It turns out it was a simple case of using JavaExec
(I was new to that anyway):
task runBenchmark(type: JavaExec, dependsOn: test) {
def vmVer = System.getProperty('java.version')
def osName = System.getProperty('os.name').replaceAll('\\s','')
def osArch = System.getProperty('os.arch')
def fnameBase = "ver${version}_${osName}-${osArch}_jvm${vmVer}"
def benchMarksDir = "${project.buildDir}/benchmarks"
ant.mkdir(dir: benchMarksDir)
def outStream = new FileOutputStream("${benchMarksDir}/${fnameBase}-out.txt")
standardOutput = outStream
main = 'org.funcito.benchmarks.MyBenchmark'
classpath = sourceSets.test.runtimeClasspath
args = ['--saveResults', "${benchMarksDir}/${fnameBase}.json", '-Jmode=-server,-client']
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With