Skip to content

Commit bcf2d91

Browse files
author
Abduqodiri Qurbonzoda
committed
Convert benchmarks to multi-platform project
1 parent b549033 commit bcf2d91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+190
-216
lines changed

benchmarks-mpp/build.gradle

Lines changed: 0 additions & 53 deletions
This file was deleted.

benchmarks/build.gradle.kts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import kotlinx.benchmark.gradle.JvmBenchmarkTarget
2+
import org.gradle.jvm.tasks.Jar
3+
4+
plugins {
5+
id("kotlin-multiplatform")
6+
id("kotlinx.benchmark") version "0.2.0-dev-6"
7+
}
8+
9+
10+
evaluationDependsOn(":kotlinx-collections-immutable")
11+
12+
val JDK_6: String by project
13+
14+
repositories {
15+
maven(url = "https://dl.bintray.com/kotlin/kotlinx")
16+
}
17+
18+
19+
kotlin {
20+
infra {
21+
target("macosX64")
22+
target("linuxX64")
23+
target("mingwX64")
24+
}
25+
26+
jvm {
27+
compilations.all {
28+
kotlinOptions {
29+
jvmTarget = "1.6"
30+
jdkHome = JDK_6
31+
}
32+
}
33+
}
34+
35+
js {
36+
nodejs {
37+
38+
}
39+
}
40+
41+
sourceSets.all {
42+
kotlin.setSrcDirs(listOf("$name/src"))
43+
resources.setSrcDirs(listOf("$name/resources"))
44+
}
45+
46+
sourceSets {
47+
commonMain {
48+
dependencies {
49+
api("org.jetbrains.kotlin:kotlin-stdlib-common")
50+
api("org.jetbrains.kotlinx:kotlinx.benchmark.runtime:0.2.0-dev-6")
51+
api(project(":kotlinx-collections-immutable"))
52+
}
53+
}
54+
}
55+
}
56+
57+
58+
// Configure benchmark
59+
benchmark {
60+
configurations {
61+
named("main") {
62+
warmups = 7
63+
iterations = 7
64+
iterationTime = 500
65+
iterationTimeUnit = "ms"
66+
param("size", "1", "10", "100", "1000", "10000")
67+
param("immutablePercentage", /*"95", "30", */"0")
68+
param("hashCodeType", "random", "collision")
69+
}
70+
}
71+
72+
targets {
73+
register("jvm") {
74+
this as JvmBenchmarkTarget
75+
jmhVersion = "1.21"
76+
}
77+
register("js")
78+
register("native")
79+
register("macosX64")
80+
register("linuxX64")
81+
register("mingwX64")
82+
}
83+
}
84+
85+
val benchmarksJar: Configuration by configurations.creating
86+
87+
afterEvaluate {
88+
val jvmBenchmarkJar by tasks.getting(Jar::class)
89+
artifacts.add("benchmarksJar", jvmBenchmarkJar)
90+
}

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/ObjectWrapper.kt renamed to benchmarks/commonMain/src/benchmarks/ObjectWrapper.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
*/
55

66
package benchmarks
7+
import kotlin.js.JsName
78

8-
class ObjectWrapper<K: Comparable<K>>(val obj: K, val hashCode: Int) : Comparable<ObjectWrapper<K>> {
9+
class ObjectWrapper<K: Comparable<K>>(
10+
val obj: K,
11+
@JsName("_hashCode") val hashCode: Int
12+
) : Comparable<ObjectWrapper<K>> {
913
override fun hashCode(): Int {
1014
return hashCode
1115
}
@@ -14,7 +18,6 @@ class ObjectWrapper<K: Comparable<K>>(val obj: K, val hashCode: Int) : Comparabl
1418
if (other !is ObjectWrapper<*>) {
1519
return false
1620
}
17-
assert(obj != other.obj || hashCode == other.hashCode) // if elements are equal hashCodes must be equal
1821
return obj == other.obj
1922
}
2023

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/hashCodeTypes.kt renamed to benchmarks/commonMain/src/benchmarks/hashCodeTypes.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package benchmarks
77

8-
import java.util.*
9-
108
const val ASCENDING_HASH_CODE = "ascending"
119
const val RANDOM_HASH_CODE = "random"
1210
const val COLLISION_HASH_CODE = "collision"
@@ -21,7 +19,7 @@ private inline fun intWrappers(size: Int, hashCodeGenerator: (index: Int) -> Int
2119
}
2220

2321
private fun generateIntWrappers(hashCodeType: String, size: Int): List<IntWrapper> {
24-
val random = Random(40)
22+
val random = kotlin.random.Random(40)
2523
return when(hashCodeType) {
2624
ASCENDING_HASH_CODE -> intWrappers(size) { it }
2725
RANDOM_HASH_CODE,

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Add.kt renamed to benchmarks/commonMain/src/benchmarks/immutableList/Add.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ package benchmarks.immutableList
77

88
import benchmarks.*
99
import kotlinx.collections.immutable.ImmutableList
10-
import org.openjdk.jmh.annotations.*
11-
import org.openjdk.jmh.infra.Blackhole
10+
import kotlinx.benchmark.*
1211

13-
@State(Scope.Thread)
12+
@State(Scope.Benchmark)
1413
open class Add {
1514
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
1615
var size: Int = 0

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/AddAll.kt renamed to benchmarks/commonMain/src/benchmarks/immutableList/AddAll.kt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
/*
22
* Copyright 2016-2019 JetBrains s.r.o.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
154
*/
165

176
package benchmarks.immutableList
187

198
import benchmarks.*
209
import kotlinx.collections.immutable.ImmutableList
2110
import kotlinx.collections.immutable.persistentListOf
22-
import org.openjdk.jmh.annotations.*
11+
import kotlinx.benchmark.*
2312

24-
@State(Scope.Thread)
13+
@State(Scope.Benchmark)
2514
open class AddAll {
2615
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
2716
var size: Int = 0

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Get.kt renamed to benchmarks/commonMain/src/benchmarks/immutableList/Get.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ package benchmarks.immutableList
88
import benchmarks.*
99
import kotlinx.collections.immutable.PersistentList
1010
import kotlinx.collections.immutable.persistentListOf
11-
import org.openjdk.jmh.annotations.*
12-
import org.openjdk.jmh.infra.Blackhole
11+
import kotlinx.benchmark.*
1312

1413
@State(Scope.Benchmark)
1514
open class Get {
@@ -18,7 +17,7 @@ open class Get {
1817

1918
private var persistentList: PersistentList<String> = persistentListOf()
2019

21-
@Setup(Level.Trial)
20+
@Setup
2221
fun prepare() {
2322
persistentList = persistentListAdd(size)
2423
}

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Iterate.kt renamed to benchmarks/commonMain/src/benchmarks/immutableList/Iterate.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ package benchmarks.immutableList
88
import benchmarks.*
99
import kotlinx.collections.immutable.PersistentList
1010
import kotlinx.collections.immutable.persistentListOf
11-
import org.openjdk.jmh.annotations.*
12-
import org.openjdk.jmh.infra.Blackhole
11+
import kotlinx.benchmark.*
1312

1413
@State(Scope.Benchmark)
1514
open class Iterate {
@@ -18,7 +17,7 @@ open class Iterate {
1817

1918
private var persistentList: PersistentList<String> = persistentListOf()
2019

21-
@Setup(Level.Trial)
20+
@Setup
2221
fun prepare() {
2322
persistentList = persistentListAdd(size)
2423
}

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Remove.kt renamed to benchmarks/commonMain/src/benchmarks/immutableList/Remove.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import benchmarks.*
99
import kotlinx.collections.immutable.ImmutableList
1010
import kotlinx.collections.immutable.PersistentList
1111
import kotlinx.collections.immutable.persistentListOf
12-
import org.openjdk.jmh.annotations.*
12+
import kotlinx.benchmark.*
1313

14-
@State(Scope.Thread)
14+
@State(Scope.Benchmark)
1515
open class Remove {
1616
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
1717
var size: Int = 0
1818

1919
private var persistentList: PersistentList<String> = persistentListOf()
2020

21-
@Setup(Level.Trial)
21+
@Setup
2222
fun prepare() {
2323
persistentList = persistentListAdd(size)
2424
}

0 commit comments

Comments
 (0)