import groovy.json.JsonSlurper import org.gradle.api.* /** * Utility for printing benchmark results. * Results can be obtained with JMH flags * -rf json -rff serialization-benchmark-results.json */ class PrintBenchmarksTask extends DefaultTask { private String fileName = "serialization-benchmark-results.json" @TaskAction def printBenchmarkJsonAsTeamcityStats() { File jsonFile = project.file(fileName) if (!jsonFile.exists()) throw new TaskExecutionException(this, new FileNotFoundException("File $fileName not found")) def parsedJson = new JsonSlurper().parseText(jsonFile.text) parsedJson.each { v -> def name = (v.benchmark - "kotlinx.benchmarks.") def score = v.primaryMetric.score println("##teamcity[buildStatisticValue key='" + name + "' value='" + score + "']") } } } rootProject.tasks.register("printBenchmarksJsonAsTeamcityStats", PrintBenchmarksTask)