Skip to content

Commit 4ee4f92

Browse files
author
Abduqodiri Qurbonzoda
committed
Benchmarking other immutable collections libraries
1 parent 92d2e54 commit 4ee4f92

File tree

116 files changed

+11350
-0
lines changed

Some content is hidden

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

116 files changed

+11350
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/.idea/*
22
!/.idea/copyright
3+
/benchmarks-libraries/.idea/*
4+
!/benchmarks-libraries/.idea/copyright
35
.gradle
46
*.iml
57
target

benchmarks-libraries/.idea/copyright/apache_2_0.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks-libraries/.idea/copyright/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks-libraries/build.gradle

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
plugins {
2+
id 'org.jetbrains.kotlin.jvm' version '1.3.40'
3+
id "me.champeau.gradle.jmh" version "0.4.8"
4+
}
5+
6+
repositories {
7+
mavenLocal()
8+
mavenCentral()
9+
jcenter()
10+
maven { url 'http://nexus.usethesource.io/content/repositories/public/' }
11+
}
12+
13+
dependencies {
14+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
15+
16+
implementation 'org.jetbrains.kotlinx:kotlinx-collections-immutable:0.2-SNAPSHOT'
17+
implementation 'io.usethesource:capsule:0.6.1'
18+
implementation 'org.organicdesign:Paguro:3.1.2'
19+
implementation 'com.oath.cyclops:cyclops:10.3.0'
20+
implementation 'org.clojure:clojure:1.10.0'
21+
implementation 'org.scala-lang:scala-library:2.13.0'
22+
implementation 'io.vavr:vavr:0.9.3'
23+
}
24+
25+
compileKotlin {
26+
kotlinOptions.jvmTarget = "1.8"
27+
}
28+
29+
compileJmhKotlin {
30+
kotlinOptions.jvmTarget = "1.8"
31+
}
32+
33+
task generateBenchmarkSources(type: JavaExec) {
34+
main = 'generators.BenchmarkSourceGeneratorKt'
35+
classpath = sourceSets.main.runtimeClasspath
36+
}
37+
38+
jmh {
39+
// include = ['immutableList.*.Add', 'immutableMap', 'immutableSet']
40+
// exclude = ['builder']
41+
42+
profilers = ['gc']
43+
44+
resultFormat = "csv"
45+
46+
fork = 1
47+
warmupIterations = 7
48+
iterations = 10
49+
warmup = '500ms'
50+
timeOnIteration = '500ms'
51+
52+
benchmarkMode = ['avgt']
53+
timeUnit = "us"
54+
55+
benchmarkParameters = [
56+
'size':['1', '10', '100', '1000', '10000'],
57+
// 'implementation': ['hash'],
58+
'hashCodeType':['random', 'collision'],
59+
'immutablePercentage':['0.0', '80.0']
60+
]
61+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Tue Jun 11 01:45:01 MSK 2019
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-all.zip

benchmarks-libraries/settings.gradle

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
rootProject.name = 'Collection Frameworks Benchmarks'
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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.clojure
20+
21+
import org.openjdk.jmh.annotations.*
22+
import java.util.concurrent.TimeUnit
23+
import org.openjdk.jmh.infra.Blackhole
24+
import benchmarks.*
25+
26+
@State(Scope.Thread)
27+
open class Add {
28+
@Param("10000", "100000")
29+
var size: Int = 0
30+
31+
@Benchmark
32+
fun addLast(): clojure.lang.PersistentVector {
33+
return persistentListAdd(size)
34+
}
35+
36+
@Benchmark
37+
fun addLastAndIterate(bh: Blackhole) {
38+
val list = persistentListAdd(size)
39+
for (e in list) {
40+
bh.consume(e)
41+
}
42+
}
43+
44+
@Benchmark
45+
fun addLastAndGet(bh: Blackhole) {
46+
val list = persistentListAdd(size)
47+
for (i in 0 until size) {
48+
bh.consume(list.get(i))
49+
}
50+
}
51+
}
52+
53+
54+
@State(Scope.Thread)
55+
open class Get {
56+
@Param("10000", "100000")
57+
var size: Int = 0
58+
59+
private var persistentList = clojure.lang.PersistentVector.EMPTY
60+
61+
@Setup(Level.Trial)
62+
fun prepare() {
63+
persistentList = persistentListAdd(size)
64+
}
65+
66+
@Benchmark
67+
fun getByIndex(bh: Blackhole) {
68+
for (i in 0 until size) {
69+
bh.consume(persistentList.get(i))
70+
}
71+
}
72+
}
73+
74+
75+
@State(Scope.Thread)
76+
open class Iterate {
77+
@Param("10000", "100000")
78+
var size: Int = 0
79+
80+
private var persistentList = clojure.lang.PersistentVector.EMPTY
81+
82+
@Setup(Level.Trial)
83+
fun prepare() {
84+
persistentList = persistentListAdd(size)
85+
}
86+
87+
@Benchmark
88+
fun firstToLast(bh: Blackhole) {
89+
for (e in persistentList) {
90+
bh.consume(e)
91+
}
92+
}
93+
94+
@Benchmark
95+
fun lastToFirst(bh: Blackhole) {
96+
val iterator = persistentList.listIterator(size)
97+
98+
while (iterator.hasPrevious()) {
99+
bh.consume(iterator.previous())
100+
}
101+
}
102+
}
103+
104+
105+
@State(Scope.Thread)
106+
open class Remove {
107+
@Param("10000", "100000")
108+
var size: Int = 0
109+
110+
private var persistentList = clojure.lang.PersistentVector.EMPTY
111+
112+
@Setup(Level.Trial)
113+
fun prepare() {
114+
persistentList = persistentListAdd(size)
115+
}
116+
117+
@Benchmark
118+
fun removeLast(): clojure.lang.PersistentVector {
119+
var list = persistentList
120+
repeat(times = size) {
121+
list = list.pop()
122+
}
123+
return list
124+
}
125+
}
126+
127+
128+
@State(Scope.Thread)
129+
open class Set {
130+
@Param("10000", "100000")
131+
var size: Int = 0
132+
133+
private var persistentList = clojure.lang.PersistentVector.EMPTY
134+
private var randomIndices = listOf<Int>()
135+
136+
@Setup(Level.Trial)
137+
fun prepare() {
138+
persistentList = persistentListAdd(size)
139+
randomIndices = List(size) { it }.shuffled()
140+
}
141+
142+
@Benchmark
143+
fun setByIndex(): clojure.lang.PersistentVector {
144+
repeat(times = size) { index ->
145+
persistentList = persistentList.assocN(index, "another element")
146+
}
147+
return persistentList
148+
}
149+
150+
@Benchmark
151+
fun setByRandomIndex(): clojure.lang.PersistentVector {
152+
repeat(times = size) { index ->
153+
persistentList = persistentList.assocN(randomIndices[index], "another element")
154+
}
155+
return persistentList
156+
}
157+
}
158+
159+
160+
private fun persistentListAdd(size: Int): clojure.lang.PersistentVector {
161+
var list = clojure.lang.PersistentVector.EMPTY
162+
repeat(times = size) {
163+
list = list.cons("some element")
164+
}
165+
return list
166+
}

0 commit comments

Comments
 (0)