From 403c77468858a116d714041fad458851be6e7a1c Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Mon, 28 Aug 2017 13:49:47 +0300 Subject: [PATCH] [performance] compilation and execution with kotlin native and jvm, comparing results --- build.gradle | 3 +- gradle.properties | 7 ++- performance/build.gradle | 101 +++++++++++++++++++++++++++++++++++++-- settings.gradle | 2 +- 4 files changed, 106 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 1e711479514..abc4e0e8dd8 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,7 @@ ext { dependenciesDir = rootProject.file("dist/dependencies") clangManager = new ClangManager(konanProperties, dependenciesDir.absolutePath) + kotlinCompilerModule="org.jetbrains.kotlin:kotlin-compiler:${kotlinVersion}" } allprojects { @@ -314,7 +315,7 @@ task performance(type: GradleBuild) { dependsOn ':tools:kotlin-native-gradle-plugin:jar' dir = 'performance' - tasks = ['build', 'run'] + tasks = ['build', 'bench'] doFirst { startParameter.projectProperties['konanPluginClasspath'] = diff --git a/gradle.properties b/gradle.properties index 8be9ff6bd82..aa1e5483f39 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,6 +23,11 @@ testDataVersion=1067176:id kotlinCompilerRepo=https://dl.bintray.com/jetbrains/kotlin-native-dependencies #kotlinCompilerRepo=http://oss.sonatype.org/content/repositories/snapshots #kotlinCompilerRepo=http://dl.bintray.com/kotlin/kotlin-dev -kotlinCompilerModule=org.jetbrains.kotlin:kotlin-compiler:1.1-20170826.093556-820 +kotlinVersion=1.1-20170826.093556-820 konanVersion=0.3.1 org.gradle.jvmargs='-Dfile.encoding=UTF-8' + +## +# required for performance mesuarement tasks +kotlinStdLibJdk8Version=1.1-20170822.213444-718 +kotlinGradlePluginVersion=1.1-20170821.192225-785 diff --git a/performance/build.gradle b/performance/build.gradle index eec49c19d0c..4bdc298083b 100644 --- a/performance/build.gradle +++ b/performance/build.gradle @@ -1,20 +1,113 @@ +import org.jetbrains.kotlin.konan.target.KonanTarget + +//evaluationDependsOn(":tools:kotlin-native-gradle-plugin") + buildscript { + def rootProperties = new Properties() + rootProperties.load(new FileReader(project.file('../gradle.properties'))) + rootProperties.each {k, v -> ext.set(k, v)} repositories { - mavenCentral() + maven { - url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" + //TODO: this path should be removed!! + url "https://oss.sonatype.org/content/repositories/snapshots" } + maven { + url rootProperties.kotlinCompilerRepo + } + mavenCentral() } dependencies { - classpath files(konanPluginClasspath) + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinGradlePluginVersion" + classpath files(project.file('../tools/kotlin-native-gradle-plugin/build/libs').listFiles().findAll{it.name.endsWith('.jar')}.collect().first().absolutePath) } } +repositories { + maven { + //TODO: this path should be removed!! + url "https://oss.sonatype.org/content/repositories/snapshots" + } + maven { + url kotlinCompilerRepo + } + mavenCentral() +} + +//TODO: property +def ringWarmup=1000 +def iterations=2000 + +apply plugin: 'kotlin' +apply plugin: 'application' apply plugin: 'konan' konanArtifacts { Ring { enableOptimization() } -} \ No newline at end of file +} + +compileKotlin { + kotlinOptions.suppressWarnings = true + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlinStdLibJdk8Version" +} + +task jvmRun(type: JavaExec) { + def output = new FileOutputStream("${buildDir.absolutePath}/jvmReport.txt") + classpath sourceSets.main.runtimeClasspath + main = "MainKt" + args "$ringWarmup", "$iterations" + standardOutput = output + doLast { + output.close() + } +} + +task konanRun(type: Exec) { + def output = new FileOutputStream("${buildDir.absolutePath}/konanReport.txt") + commandLine project.file("build/konan/bin/Ring.kexe").absolutePath, "$ringWarmup", "$iterations" + standardOutput = output + doLast { + output.close() + } +} + +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")) + jvmReport.report.each { k, v -> + def ratio = String.format('%.2f', konanReport.report[k]/v * 100) + println("$k : $ratio %") + if (System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE") != null) + println("##teamcity[buildStatisticValue key='$k' value='$ratio']") + } + } +} + + +class Report { + def Map report = new HashMap() + + Report(File path) { + path.readLines().drop(3).takeWhile { it.split(':').length == 2 }.each { + def p = it.split(':') + report.put(p[0].trim(), Double.parseDouble(p[1].trim())) + } + } +} diff --git a/settings.gradle b/settings.gradle index e06e588e9dd..24b2f4efa1d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,4 +27,4 @@ include ':common' include ':backend.native:tests' include ':shared' include ':tools:kotlin-native-gradle-plugin' -include ':utilities' \ No newline at end of file +include ':utilities'