Skip to content

Commit

Permalink
Enable performance testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinAnisimov committed Aug 3, 2017
1 parent df754c0 commit b3fe93c
Show file tree
Hide file tree
Showing 33 changed files with 3,358 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ proto/compiler/tests
proto/compiler/google/src/google/protobuf/compiler/kotlin/bin
proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc

peformance/build

# translator auto generated artifacts
kotstd/ll

Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ task bundle(type: (isWindows()) ? Zip : Tar) {
}
}

task performance {
dependsOn 'dist'
dependsOn ':performance:build'
dependsOn ':performance:run'
}

task clean {
doLast {
file('dist').traverse(type: FileType.ANY, excludeNameFilter: "dependencies", maxDepth: 0) {
Expand Down
21 changes: 21 additions & 0 deletions performance/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
buildscript {
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
}
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:+"
}
}

apply plugin: 'konan'

konanArtifacts {
Ring {
enableOptimization()
}
}
1 change: 1 addition & 0 deletions performance/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
konan.home=../dist
14 changes: 14 additions & 0 deletions performance/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.jetbrains.ring.Launcher

fun main(args: Array<String>) {
var numWarmIterations = 0 // Should be 100000 for jdk based run
var numMeasureIterations = 2000

if (args.size == 2) {
numWarmIterations = args[0].toInt()
numMeasureIterations = args[1].toInt()
}

val average = Launcher(numWarmIterations, numMeasureIterations).runBenchmarks()
println("\nRingAverage: $average\n")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jetbrains.ring

/**
* Created by Mikhail.Glukhikh on 06/03/2015.
*
* A benchmark for a single abstract method based on a string comparison
*/

open class AbstractMethodBenchmark {

private val arr: List<String> = zdf_win
private val sequence = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"

private val sequenceMap = HashMap<Char, Int>()

init {
var i = 0;
for (ch in sequence) {
sequenceMap[ch] = i++;
}
}

//Benchmark
fun sortStrings(): Set<String> {
val res = arr.subList(0, if (BENCHMARK_SIZE < arr.size) BENCHMARK_SIZE else arr.size).toSet()
return res
}

//Benchmark
fun sortStringsWithComparator(): Set<String> {
val res = mutableSetOf<String>()
res.addAll(arr.subList(0, if (BENCHMARK_SIZE < arr.size) BENCHMARK_SIZE else arr.size))
return res
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.jetbrains.ring

open class ClassArrayBenchmark {
private var _data: Array<Value>? = null
val data: Array<Value>
get() = _data!!

fun setup() {
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (n in classValues(BENCHMARK_SIZE))
list.add(n)
_data = list.toTypedArray()
}

//Benchmark
fun copy(): List<Value> {
return data.toList()
}

//Benchmark
fun copyManual(): List<Value> {
val list = ArrayList<Value>(data.size)
for (item in data) {
list.add(item)
}
return list
}

//Benchmark
fun filterAndCount(): Int {
return data.filter { filterLoad(it) }.count()
}

//Benchmark
fun filterAndMap(): List<String> {
return data.filter { filterLoad(it) }.map { mapLoad(it) }
}

//Benchmark
fun filterAndMapManual(): ArrayList<String> {
val list = ArrayList<String>()
for (it in data) {
if (filterLoad(it)) {
val value = mapLoad(it)
list.add(value)
}
}
return list
}

//Benchmark
fun filter(): List<Value> {
return data.filter { filterLoad(it) }
}

//Benchmark
fun filterManual(): List<Value> {
val list = ArrayList<Value>()
for (it in data) {
if (filterLoad(it))
list.add(it)
}
return list
}

//Benchmark
fun countFilteredManual(): Int {
var count = 0
for (it in data) {
if (filterLoad(it))
count++
}
return count
}

//Benchmark
fun countFiltered(): Int {
return data.count { filterLoad(it) }
}

//Benchmark
fun countFilteredLocal(): Int {
return data.cnt { filterLoad(it) }
}

//Benchmark
// fun reduce(): Int {
// return data.fold(0) { acc, it -> if (filterLoad(it)) acc + 1 else acc }
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.jetbrains.ring

open class ClassBaselineBenchmark {

//Benchmark
fun consume() {
for (item in 1..BENCHMARK_SIZE) {
Blackhole.consume(Value(item))
}
}

//Benchmark
fun consumeField() {
val value = Value(0)
for (item in 1..BENCHMARK_SIZE) {
value.value = item
Blackhole.consume(value)
}
}

//Benchmark
fun allocateList(): List<Value> {
val list = ArrayList<Value>(BENCHMARK_SIZE)
return list
}

//Benchmark
fun allocateArray(): Array<Value?> {
val list = arrayOfNulls<Value>(BENCHMARK_SIZE)
return list
}

//Benchmark
fun allocateListAndFill(): List<Value> {
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (item in 1..BENCHMARK_SIZE) {
list.add(Value(item))
}
return list
}

//Benchmark
fun allocateListAndWrite(): List<Value> {
val value = Value(0)
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (item in 1..BENCHMARK_SIZE) {
list.add(value)
}
return list
}

//Benchmark
fun allocateArrayAndFill(): Array<Value?> {
val list = arrayOfNulls<Value>(BENCHMARK_SIZE)
var index = 0
for (item in 1..BENCHMARK_SIZE) {
list[index++] = Value(item)
}
return list
}
}
120 changes: 120 additions & 0 deletions performance/src/main/kotlin/org/jetbrains/ring/ClassListBenchmark.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package org.jetbrains.ring

open class ClassListBenchmark {
private var _data: ArrayList<Value>? = null
val data: ArrayList<Value>
get() = _data!!

fun setup() {
val list = ArrayList<Value>(BENCHMARK_SIZE)
for (n in classValues(BENCHMARK_SIZE))
list.add(n)
_data = list
}

//Benchmark
fun copy(): List<Value> {
return data.toList()
}

//Benchmark
fun copyManual(): List<Value> {
val list = ArrayList<Value>(data.size)
for (item in data) {
list.add(item)
}
return list
}

//Benchmark
fun filterAndCount(): Int {
return data.filter { filterLoad(it) }.count()
}

//Benchmark
fun filterAndCountWithLambda(): Int {
return data.filter { it.value % 2 == 0 }.count()
}

//Benchmark
fun filterWithLambda(): List<Value> {
return data.filter { it.value % 2 == 0 }
}

//Benchmark
fun mapWithLambda(): List<String> {
return data.map { it.toString() }
}

//Benchmark
fun countWithLambda(): Int {
return data.count { it.value % 2 == 0 }
}

//Benchmark
fun filterAndMapWithLambda(): List<String> {
return data.filter { it.value % 2 == 0 }.map { it.toString() }
}

//Benchmark
fun filterAndMapWithLambdaAsSequence(): List<String> {
return data.asSequence().filter { it.value % 2 == 0 }.map { it.toString() }.toList()
}

//Benchmark
fun filterAndMap(): List<String> {
return data.filter { filterLoad(it) }.map { mapLoad(it) }
}

//Benchmark
fun filterAndMapManual(): ArrayList<String> {
val list = ArrayList<String>()
for (it in data) {
if (filterLoad(it)) {
val value = mapLoad(it)
list.add(value)
}
}
return list
}

//Benchmark
fun filter(): List<Value> {
return data.filter { filterLoad(it) }
}

//Benchmark
fun filterManual(): List<Value> {
val list = ArrayList<Value>()
for (it in data) {
if (filterLoad(it))
list.add(it)
}
return list
}

//Benchmark
fun countFilteredManual(): Int {
var count = 0
for (it in data) {
if (filterLoad(it))
count++
}
return count
}

//Benchmark
fun countFiltered(): Int {
return data.count { filterLoad(it) }
}

//Benchmark
// fun countFilteredLocal(): Int {
// return data.cnt { filterLoad(it) }
// }

//Benchmark
fun reduce(): Int {
return data.fold(0) { acc, it -> if (filterLoad(it)) acc + 1 else acc }
}
}
Loading

0 comments on commit b3fe93c

Please sign in to comment.