Skip to content

Commit

Permalink
[performance] compilation and execution with kotlin native and jvm, c…
Browse files Browse the repository at this point in the history
…omparing results
  • Loading branch information
vvlevchenko committed Aug 29, 2017
1 parent 136c62a commit 403c774
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 7 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ext {

dependenciesDir = rootProject.file("dist/dependencies")
clangManager = new ClangManager(konanProperties, dependenciesDir.absolutePath)
kotlinCompilerModule="org.jetbrains.kotlin:kotlin-compiler:${kotlinVersion}"
}

allprojects {
Expand Down Expand Up @@ -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'] =
Expand Down
7 changes: 6 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
101 changes: 97 additions & 4 deletions performance/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
//TODO: this path should be removed!!
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven {
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
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()
}
}
}

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<String, Double> 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()))
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ include ':common'
include ':backend.native:tests'
include ':shared'
include ':tools:kotlin-native-gradle-plugin'
include ':utilities'
include ':utilities'

0 comments on commit 403c774

Please sign in to comment.