forked from JetBrains/kotlin-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df754c0
commit b3fe93c
Showing
33 changed files
with
3,358 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
konan.home=../dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
36 changes: 36 additions & 0 deletions
36
performance/src/main/kotlin/org/jetbrains/ring/AbstractMethodBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
90 changes: 90 additions & 0 deletions
90
performance/src/main/kotlin/org/jetbrains/ring/ClassArrayBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
// } | ||
} |
61 changes: 61 additions & 0 deletions
61
performance/src/main/kotlin/org/jetbrains/ring/ClassBaselineBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
120
performance/src/main/kotlin/org/jetbrains/ring/ClassListBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |
Oops, something went wrong.