Skip to content

Commit 983c25d

Browse files
author
Abduqodiri Qurbonzoda
committed
Benchmarking other immutable collections libraries
1 parent a3389c1 commit 983c25d

File tree

139 files changed

+7841
-1
lines changed

Some content is hidden

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

139 files changed

+7841
-1
lines changed

benchmarks-libraries/build.gradle

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
3+
id "me.champeau.gradle.jmh" version "0.4.8"
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
jcenter()
9+
maven { url 'http://nexus.usethesource.io/content/repositories/public/' }
10+
}
11+
12+
dependencies {
13+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
14+
15+
implementation project(path: ':kotlinx-collections-immutable')
16+
implementation 'io.usethesource:capsule:0.6.1'
17+
implementation 'org.organicdesign:Paguro:3.1.2'
18+
}
19+
20+
compileKotlin {
21+
kotlinOptions.jvmTarget = "1.8"
22+
}
23+
24+
jmh {
25+
include = ['immutableList', 'immutableMap', 'immutableSet']
26+
exclude = ['builder']
27+
28+
warmup = '1s'
29+
warmupIterations = 5
30+
timeOnIteration = '1s'
31+
iterations = 5
32+
benchmarkMode = ['avgt']
33+
benchmarkParameters = [
34+
'size':['10000'],
35+
'implementation': ['hash'],
36+
'hashCodeType':['random'],
37+
'immutablePercentage':['0']
38+
]
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* 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.
15+
*/
16+
17+
// Auto-generated file. DO NOT EDIT!
18+
19+
package benchmarks
20+
21+
22+
class IntWrapper(val obj: Int, val hashCode: Int) : Comparable<IntWrapper> {
23+
override fun hashCode(): Int {
24+
return hashCode
25+
}
26+
27+
override fun equals(other: Any?): Boolean {
28+
if (other !is IntWrapper) {
29+
return false
30+
}
31+
assert(obj != other.obj || hashCode == other.hashCode) // if elements are equal hashCodes must be equal
32+
return obj == other.obj
33+
}
34+
35+
override fun compareTo(other: IntWrapper): Int {
36+
return obj.compareTo(other.obj)
37+
}
38+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* 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.
15+
*/
16+
17+
// Auto-generated file. DO NOT EDIT!
18+
19+
package benchmarks.immutableList.kotlin
20+
21+
import org.openjdk.jmh.annotations.*
22+
import java.util.concurrent.TimeUnit
23+
import org.openjdk.jmh.infra.Blackhole
24+
25+
@Fork(1)
26+
@Warmup(iterations = 5)
27+
@Measurement(iterations = 5)
28+
@BenchmarkMode(Mode.AverageTime)
29+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
30+
@State(Scope.Thread)
31+
open class Add {
32+
@Param("10000", "100000")
33+
var size: Int = 0
34+
35+
@Benchmark
36+
fun addLast(): kotlinx.collections.immutable.PersistentList<String> {
37+
return persistentListAdd(size)
38+
}
39+
40+
@Benchmark
41+
fun addLastAndIterate(bh: Blackhole) {
42+
val list = persistentListAdd(size)
43+
for (e in list) {
44+
bh.consume(e)
45+
}
46+
}
47+
48+
@Benchmark
49+
fun addLastAndGet(bh: Blackhole) {
50+
val list = persistentListAdd(size)
51+
for (i in 0 until list.size) {
52+
bh.consume(list[i])
53+
}
54+
}
55+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* 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.
15+
*/
16+
17+
// Auto-generated file. DO NOT EDIT!
18+
19+
package benchmarks.immutableList.kotlin
20+
21+
import org.openjdk.jmh.annotations.*
22+
import java.util.concurrent.TimeUnit
23+
import org.openjdk.jmh.infra.Blackhole
24+
25+
@Fork(1)
26+
@Warmup(iterations = 5)
27+
@Measurement(iterations = 5)
28+
@BenchmarkMode(Mode.AverageTime)
29+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
30+
@State(Scope.Thread)
31+
open class Get {
32+
@Param("10000", "100000")
33+
var size: Int = 0
34+
35+
private var persistentList = kotlinx.collections.immutable.persistentListOf<String>()
36+
37+
@Setup(Level.Trial)
38+
fun prepare() {
39+
persistentList = persistentListAdd(size)
40+
}
41+
42+
@Benchmark
43+
fun getByIndex(bh: Blackhole) {
44+
for (i in 0 until persistentList.size) {
45+
bh.consume(persistentList[i])
46+
}
47+
}
48+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* 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.
15+
*/
16+
17+
// Auto-generated file. DO NOT EDIT!
18+
19+
package benchmarks.immutableList.kotlin
20+
21+
import org.openjdk.jmh.annotations.*
22+
import java.util.concurrent.TimeUnit
23+
import org.openjdk.jmh.infra.Blackhole
24+
25+
@Fork(1)
26+
@Warmup(iterations = 5)
27+
@Measurement(iterations = 5)
28+
@BenchmarkMode(Mode.AverageTime)
29+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
30+
@State(Scope.Thread)
31+
open class Iterate {
32+
@Param("10000", "100000")
33+
var size: Int = 0
34+
35+
private var persistentList = kotlinx.collections.immutable.persistentListOf<String>()
36+
37+
@Setup(Level.Trial)
38+
fun prepare() {
39+
persistentList = persistentListAdd(size)
40+
}
41+
42+
@Benchmark
43+
fun firstToLast(bh: Blackhole) {
44+
for (e in persistentList) {
45+
bh.consume(e)
46+
}
47+
}
48+
49+
@Benchmark
50+
fun lastToFirst(bh: Blackhole) {
51+
val iterator = persistentList.listIterator(size)
52+
53+
while (iterator.hasPrevious()) {
54+
bh.consume(iterator.previous())
55+
}
56+
}
57+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* 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.
15+
*/
16+
17+
// Auto-generated file. DO NOT EDIT!
18+
19+
package benchmarks.immutableList.kotlin
20+
21+
import org.openjdk.jmh.annotations.*
22+
import java.util.concurrent.TimeUnit
23+
24+
@Fork(1)
25+
@Warmup(iterations = 5)
26+
@Measurement(iterations = 5)
27+
@BenchmarkMode(Mode.AverageTime)
28+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
29+
@State(Scope.Thread)
30+
open class Remove {
31+
@Param("10000", "100000")
32+
var size: Int = 0
33+
34+
private var persistentList = kotlinx.collections.immutable.persistentListOf<String>()
35+
36+
@Setup(Level.Trial)
37+
fun prepare() {
38+
persistentList = persistentListAdd(size)
39+
}
40+
41+
@Benchmark
42+
fun removeLast(): kotlinx.collections.immutable.PersistentList<String> {
43+
var list = persistentList
44+
repeat(times = size) {
45+
list = list.removeAt(list.size - 1)
46+
}
47+
return list
48+
}
49+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* 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.
15+
*/
16+
17+
// Auto-generated file. DO NOT EDIT!
18+
19+
package benchmarks.immutableList.kotlin
20+
21+
import org.openjdk.jmh.annotations.*
22+
import java.util.concurrent.TimeUnit
23+
24+
@Fork(1)
25+
@Warmup(iterations = 5)
26+
@Measurement(iterations = 5)
27+
@BenchmarkMode(Mode.AverageTime)
28+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
29+
@State(Scope.Thread)
30+
open class Set {
31+
@Param("10000", "100000")
32+
var size: Int = 0
33+
34+
private var persistentList = kotlinx.collections.immutable.persistentListOf<String>()
35+
private var randomIndices = listOf<Int>()
36+
37+
@Setup(Level.Trial)
38+
fun prepare() {
39+
persistentList = persistentListAdd(size)
40+
randomIndices = List(size) { it }.shuffled()
41+
}
42+
43+
@Benchmark
44+
fun setByIndex(): kotlinx.collections.immutable.PersistentList<String> {
45+
repeat(times = size) { index ->
46+
persistentList = persistentList.set(index, "another element")
47+
}
48+
return persistentList
49+
}
50+
51+
@Benchmark
52+
fun setByRandomIndex(): kotlinx.collections.immutable.PersistentList<String> {
53+
repeat(times = size) { index ->
54+
persistentList = persistentList.set(randomIndices[index], "another element")
55+
}
56+
return persistentList
57+
}
58+
}

0 commit comments

Comments
 (0)