1c62b882bd
- Extracted number of attempts to a parameter - Show 95% confidence intervals instead of standard deviation
150 lines
4.1 KiB
Groovy
150 lines
4.1 KiB
Groovy
buildscript {
|
|
repositories {
|
|
maven {
|
|
url 'https://cache-redirector.jetbrains.com/maven-central'
|
|
}
|
|
maven {
|
|
url buildKotlinCompilerRepo
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$buildKotlinVersion"
|
|
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$gradlePluginVersion"
|
|
}
|
|
}
|
|
|
|
repositories {
|
|
maven {
|
|
url kotlinCompilerRepo
|
|
}
|
|
maven {
|
|
url buildKotlinCompilerRepo
|
|
}
|
|
}
|
|
|
|
//TODO: property
|
|
def jvmWarmup = 10000
|
|
def nativeWarmup = 10
|
|
def attempts = 10
|
|
|
|
ext."konan.home" = distDir
|
|
|
|
apply plugin: 'kotlin'
|
|
apply plugin: 'application'
|
|
apply plugin: 'konan'
|
|
|
|
checkKonanCompiler.dependsOn ':dist'
|
|
|
|
konanArtifacts {
|
|
program('Ring') {
|
|
srcDir 'src/main/kotlin'
|
|
srcDir 'src/main/kotlin-native'
|
|
enableOptimizations true
|
|
}
|
|
}
|
|
|
|
sourceSets {
|
|
main.kotlin.srcDir 'src/main/kotlin'
|
|
main.kotlin.srcDir 'src/main/kotlin-jvm'
|
|
}
|
|
|
|
compileKotlin {
|
|
kotlinOptions.suppressWarnings = true
|
|
kotlinOptions {
|
|
jvmTarget = "1.8"
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$buildKotlinVersion"
|
|
}
|
|
|
|
task jvmRun(type: JavaExec) {
|
|
dependsOn 'build'
|
|
def output = new ByteArrayOutputStream()
|
|
classpath sourceSets.main.runtimeClasspath
|
|
main = "MainKt"
|
|
args "$jvmWarmup", "$attempts"
|
|
standardOutput = output
|
|
doLast {
|
|
dumpReport('jvmReport', output)
|
|
}
|
|
}
|
|
|
|
private void dumpReport(String name, ByteArrayOutputStream output) {
|
|
new File("${buildDir.absolutePath}/${name}.txt").withOutputStream {
|
|
it.write(output.toByteArray())
|
|
}
|
|
}
|
|
|
|
task konanRun(type: Exec) {
|
|
dependsOn 'build'
|
|
def output = new ByteArrayOutputStream()
|
|
commandLine konanArtifacts.Ring.getByTarget('host').artifact.absolutePath, "$nativeWarmup", "$attempts"
|
|
standardOutput = output
|
|
doLast {
|
|
dumpReport('konanReport', output)
|
|
}
|
|
}
|
|
|
|
startScripts{
|
|
setEnabled(false)
|
|
}
|
|
|
|
task bench(type:DefaultTask) {
|
|
dependsOn jvmRun
|
|
dependsOn konanRun
|
|
|
|
doLast {
|
|
def jvmReport = new Report(project.file("build/jvmReport.txt"))
|
|
def konanReport = new Report(project.file("build/konanReport.txt"))
|
|
def average = "none"
|
|
def absoluteAverage = "none"
|
|
jvmReport.report
|
|
.sort { konanReport.report[it.key].mean / it.value.mean }
|
|
.each { k, v ->
|
|
def konanValue = konanReport.report[k]
|
|
def ratio = konanValue.mean / v.mean
|
|
// This is a hack since neither mean nor variance of ratio of two distributions is known.
|
|
def minRatio = (konanValue.mean - konanValue.stdDev) / (v.mean + v.stdDev)
|
|
def maxRatio = (konanValue.mean + konanValue.stdDev) / (v.mean - v.stdDev)
|
|
def ratioConfInt = Math.min(Math.abs(minRatio - ratio), Math.abs(maxRatio - ratio))
|
|
def formattedKonanValue = String.format('%.4f us +- %.4f us', konanValue.mean / 1000, konanValue.stdDev / 1000)
|
|
def formattedRatio = String.format('%.2f +- %.2f', ratio, ratioConfInt)
|
|
if (k == 'RingAverage') {
|
|
average = formattedRatio
|
|
absoluteAverage = formattedKonanValue
|
|
} else {
|
|
println("$k : absolute = $formattedKonanValue, ratio = $formattedRatio")
|
|
}
|
|
if (System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE") != null)
|
|
println("##teamcity[buildStatisticValue key='$k' value='$ratio']")
|
|
}
|
|
|
|
println()
|
|
println("Average Ring score: absolute = $absoluteAverage, ratio = $average")
|
|
}
|
|
}
|
|
|
|
class Results {
|
|
def Double mean
|
|
def Double stdDev
|
|
|
|
Results(Double mean, Double stdDev) {
|
|
this.mean = mean
|
|
this.stdDev = stdDev
|
|
}
|
|
}
|
|
|
|
class Report {
|
|
def Map<String, Results> report = new TreeMap()
|
|
|
|
Report(File path) {
|
|
path.readLines().drop(3).findAll { it.split(':').length == 3 }.each {
|
|
def p = it.split(':')
|
|
report.put(p[0].trim(), new Results(Double.parseDouble(p[1].trim()), Double.parseDouble(p[2].trim())))
|
|
}
|
|
}
|
|
}
|