Files
kotlin-fork/performance/gradle/benchmark.gradle
T
2019-05-17 17:36:44 +03:00

142 lines
5.2 KiB
Groovy

apply plugin: 'kotlin-multiplatform'
repositories {
maven {
url 'https://cache-redirector.jetbrains.com/jcenter'
}
maven {
url kotlinCompilerRepo
}
maven {
url buildKotlinCompilerRepo
}
}
private def determinePreset() {
def preset = MPPTools.defaultHostPreset(project)
println("$project has been configured for ${preset.name} platform.")
preset
}
def getMingwPath() {
def directory = System.getenv("MINGW64_DIR")
if (directory == null)
directory = "c:/msys64/mingw64"
return directory
}
def hostPreset = determinePreset()
kotlin {
sourceSets {
commonMain {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion"
}
project.ext.commonSrcDirs.forEach {
kotlin.srcDir it
}
}
nativeMain {
project.ext.nativeSrcDirs.forEach {
kotlin.srcDir it
}
}
jvmMain {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
}
project.ext.jvmSrcDirs.forEach {
kotlin.srcDir it
}
}
}
jvm() {
compilations.all {
tasks[compileKotlinTaskName].kotlinOptions {
jvmTarget = '1.8'
suppressWarnings = true
freeCompilerArgs = (project.hasProperty('compilerArgs') ? compilerArgs.split() : [])
}
}
}
targetFromPreset(hostPreset, 'native') {
compilations.main.extraOpts = (project.hasProperty('compilerArgs') ? compilerArgs.split() : []) + '-opt'
binaries {
executable('benchmark', [RELEASE]) {
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
linkerOpts = ["-L${getMingwPath()}/lib".toString()]
}
}
}
}
}
MPPTools.addTimeListener(project)
MPPTools.createRunTask(project, 'konanRun', kotlin.targets.native) {
workingDir = project.provider {
kotlin.targets.native.binaries.getExecutable("benchmark", buildType).outputDirectory
}
depends("build")
args("-w", "$nativeWarmup", "-r", "$attempts", "-o", "${buildDir.absolutePath}/${nativeBenchResults}", "-p", "${project.ext.applicationName}::")
}
task jvmRun(type: RunJvmTask) {
dependsOn 'build'
def runtimeClasspath = files(
kotlin.targets.jvm.compilations.main.output.allOutputs,
project.configurations.getByName(kotlin.targets.jvm.compilations.main.runtimeDependencyConfigurationName)
)
classpath runtimeClasspath
main = "MainKt"
args "-w", "$jvmWarmup", "-r", "$attempts", "-o", "${buildDir.absolutePath}/${jvmBenchResults}", "-p", "${project.ext.applicationName}::"
}
task konanJsonReport {
doLast {
def nativeExecutable = MPPTools.getKotlinNativeExecutable(kotlin.targets.native, "RELEASE")
def nativeCompileTime = MPPTools.getNativeCompileTime(project.ext.applicationName)
String benchContents = new File("${buildDir.absolutePath}/${nativeBenchResults}").text
def properties = getCommonProperties() + ['type': 'native',
'compilerVersion': "${konanVersion}".toString(),
'flags': kotlin.targets.native.compilations.main.extraOpts.collect{ "\"$it\"" },
'benchmarks': benchContents,
'compileTime': [nativeCompileTime],
'codeSize': MPPTools.getCodeSizeBenchmark(project.ext.applicationName, nativeExecutable) ]
def output = MPPTools.createJsonReport(properties)
new File("${buildDir.absolutePath}/${nativeJson}").write(output)
}
}
task jvmJsonReport {
doLast {
def jarPath = project.getTasks().getByName("jvmJar").archivePath
def jvmCompileTime = MPPTools.getJvmCompileTime(project.ext.applicationName)
String benchContents = new File("${buildDir.absolutePath}/${jvmBenchResults}").text
def properties = getCommonProperties() + ['type': 'jvm',
'compilerVersion': "${buildKotlinVersion}".toString(),
'benchmarks': benchContents,
'compileTime': [jvmCompileTime],
'codeSize': MPPTools.getCodeSizeBenchmark(project.ext.applicationName, "${jarPath}") ]
def output = MPPTools.createJsonReport(properties)
new File("${buildDir.absolutePath}/${jvmJson}").write(output)
}
}
jvmRun.finalizedBy jvmJsonReport
konanRun.finalizedBy konanJsonReport
private def getCommonProperties() {
return ['cpu': System.getProperty("os.arch"),
'os': System.getProperty("os.name"), // OperatingSystem.current().getName()
'jdkVersion': System.getProperty("java.version"), // org.gradle.internal.jvm.Jvm.current().javaVersion
'jdkVendor': System.getProperty("java.vendor"),
'kotlinVersion': "${kotlinVersion}".toString()]
}