forked from JetBrains/kotlin-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
124 lines (105 loc) · 2.98 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
buildscript {
repositories {
maven {
//TODO: this path should be removed!!
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven {
url kotlinCompilerRepo
}
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinGradlePluginVersion"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$konanVersion"
}
}
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'
project.setProperty("konan.home", distDir)
checkKonanCompiler.dependsOn ':dist'
konanArtifacts {
program('Ring') {
enableOptimizations true
}
}
compileKotlin {
kotlinOptions.suppressWarnings = true
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlinStdLibJdk8Version"
}
task jvmRun(type: JavaExec) {
dependsOn 'build'
def output = new ByteArrayOutputStream()
classpath sourceSets.main.runtimeClasspath
main = "MainKt"
args "$ringWarmup", "$iterations"
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, "$ringWarmup", "$iterations"
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"
jvmReport.report.each { k, v ->
def ratio = String.format('%.2f', konanReport.report[k]/v * 100)
if (k == 'RingAverage') {
average = ratio
}
println("$k : $ratio %")
if (System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE") != null)
println("##teamcity[buildStatisticValue key='$k' value='$ratio']")
}
println()
println("Average Ring score: $average %")
}
}
class Report {
def Map<String, Double> report = new HashMap()
Report(File path) {
path.readLines().drop(3).findAll { it.split(':').length == 2 }.each {
def p = it.split(':')
report.put(p[0].trim(), Double.parseDouble(p[1].trim()))
}
}
}