diff --git a/.gitignore b/.gitignore
index 15a025ce..e53a45ab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
/.idea/*
!/.idea/copyright
+/benchmarks-libraries/.idea/*
+!/benchmarks-libraries/.idea/copyright
.gradle
*.iml
target
diff --git a/benchmarks-libraries/.idea/copyright/apache_2_0.xml b/benchmarks-libraries/.idea/copyright/apache_2_0.xml
new file mode 100644
index 00000000..bb5022fc
--- /dev/null
+++ b/benchmarks-libraries/.idea/copyright/apache_2_0.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/benchmarks-libraries/.idea/copyright/profiles_settings.xml b/benchmarks-libraries/.idea/copyright/profiles_settings.xml
new file mode 100644
index 00000000..915114f1
--- /dev/null
+++ b/benchmarks-libraries/.idea/copyright/profiles_settings.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/benchmarks-libraries/build.gradle b/benchmarks-libraries/build.gradle
new file mode 100644
index 00000000..4c2572f0
--- /dev/null
+++ b/benchmarks-libraries/build.gradle
@@ -0,0 +1,61 @@
+plugins {
+ id 'org.jetbrains.kotlin.jvm' version '1.3.40'
+ id "me.champeau.gradle.jmh" version "0.4.8"
+}
+
+repositories {
+ mavenLocal()
+ mavenCentral()
+ jcenter()
+ maven { url 'http://nexus.usethesource.io/content/repositories/public/' }
+}
+
+dependencies {
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
+
+ implementation 'org.jetbrains.kotlinx:kotlinx-collections-immutable:0.2-SNAPSHOT'
+ implementation 'io.usethesource:capsule:0.6.1'
+ implementation 'org.organicdesign:Paguro:3.1.2'
+ implementation 'com.oath.cyclops:cyclops:10.3.0'
+ implementation 'org.clojure:clojure:1.10.0'
+ implementation 'org.scala-lang:scala-library:2.13.0'
+ implementation 'io.vavr:vavr:0.9.3'
+}
+
+compileKotlin {
+ kotlinOptions.jvmTarget = "1.8"
+}
+
+compileJmhKotlin {
+ kotlinOptions.jvmTarget = "1.8"
+}
+
+task generateBenchmarkSources(type: JavaExec) {
+ main = 'generators.BenchmarkSourceGeneratorKt'
+ classpath = sourceSets.main.runtimeClasspath
+}
+
+jmh {
+// include = ['immutableList.*.Add', 'immutableMap', 'immutableSet']
+// exclude = ['builder']
+
+ profilers = ['gc']
+
+ resultFormat = "csv"
+
+ fork = 1
+ warmupIterations = 7
+ iterations = 10
+ warmup = '500ms'
+ timeOnIteration = '500ms'
+
+ benchmarkMode = ['avgt']
+ timeUnit = "us"
+
+ benchmarkParameters = [
+ 'size':['1', '10', '100', '1000', '10000'],
+// 'implementation': ['hash'],
+ 'hashCodeType':['random', 'collision'],
+ 'immutablePercentage':['0.0', '80.0']
+ ]
+}
\ No newline at end of file
diff --git a/benchmarks-libraries/gradle/wrapper/gradle-wrapper.jar b/benchmarks-libraries/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 00000000..91ca28c8
Binary files /dev/null and b/benchmarks-libraries/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/benchmarks-libraries/gradle/wrapper/gradle-wrapper.properties b/benchmarks-libraries/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..29c490fc
--- /dev/null
+++ b/benchmarks-libraries/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Tue Jun 11 01:45:01 MSK 2019
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-all.zip
diff --git a/benchmarks-libraries/settings.gradle b/benchmarks-libraries/settings.gradle
new file mode 100644
index 00000000..2a56bba5
--- /dev/null
+++ b/benchmarks-libraries/settings.gradle
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+rootProject.name = 'Collection Frameworks Benchmarks'
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/IntWrapper.kt b/benchmarks-libraries/src/jmh/java/benchmarks/IntWrapper.kt
new file mode 100644
index 00000000..bf5e903f
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/IntWrapper.kt
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks
+
+
+class IntWrapper(val obj: Int, val hashCode: Int) : Comparable {
+ override fun hashCode(): Int {
+ return hashCode
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (other !is IntWrapper) {
+ return false
+ }
+ assert(obj != other.obj || hashCode == other.hashCode) // if elements are equal hashCodes must be equal
+ return obj == other.obj
+ }
+
+ override fun compareTo(other: IntWrapper): Int {
+ return obj.compareTo(other.obj)
+ }
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/clojure/List.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/clojure/List.kt
new file mode 100644
index 00000000..9d622223
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/clojure/List.kt
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableList.clojure
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Add {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Benchmark
+ fun addLast(): clojure.lang.PersistentVector {
+ return persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun addLastAndIterate(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (e in list) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun addLastAndGet(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (i in 0 until size) {
+ bh.consume(list.get(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = clojure.lang.PersistentVector.EMPTY
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun getByIndex(bh: Blackhole) {
+ for (i in 0 until size) {
+ bh.consume(persistentList.get(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = clojure.lang.PersistentVector.EMPTY
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun firstToLast(bh: Blackhole) {
+ for (e in persistentList) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun lastToFirst(bh: Blackhole) {
+ val iterator = persistentList.listIterator(size)
+
+ while (iterator.hasPrevious()) {
+ bh.consume(iterator.previous())
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = clojure.lang.PersistentVector.EMPTY
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun removeLast(): clojure.lang.PersistentVector {
+ var list = persistentList
+ repeat(times = size) {
+ list = list.pop()
+ }
+ return list
+ }
+}
+
+
+@State(Scope.Thread)
+open class Set {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = clojure.lang.PersistentVector.EMPTY
+ private var randomIndices = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ randomIndices = List(size) { it }.shuffled()
+ }
+
+ @Benchmark
+ fun setByIndex(): clojure.lang.PersistentVector {
+ repeat(times = size) { index ->
+ persistentList = persistentList.assocN(index, "another element")
+ }
+ return persistentList
+ }
+
+ @Benchmark
+ fun setByRandomIndex(): clojure.lang.PersistentVector {
+ repeat(times = size) { index ->
+ persistentList = persistentList.assocN(randomIndices[index], "another element")
+ }
+ return persistentList
+ }
+}
+
+
+private fun persistentListAdd(size: Int): clojure.lang.PersistentVector {
+ var list = clojure.lang.PersistentVector.EMPTY
+ repeat(times = size) {
+ list = list.cons("some element")
+ }
+ return list
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/clojure/builder/ListBuilder.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/clojure/builder/ListBuilder.kt
new file mode 100644
index 00000000..d833b2f6
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/clojure/builder/ListBuilder.kt
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableList.clojure.builder
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Add {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ @Benchmark
+ fun addLast(): clojure.lang.ITransientVector {
+ return persistentListBuilderAdd(size, immutablePercentage)
+ }
+
+ @Benchmark
+ fun addLastAndGet(bh: Blackhole) {
+ val builder = persistentListBuilderAdd(size, immutablePercentage)
+ for (i in 0 until size) {
+ bh.consume(builder.valAt(i))
+ }
+ }
+
+
+}
+
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder: clojure.lang.ITransientVector = clojure.lang.PersistentVector.EMPTY.asTransient() as clojure.lang.ITransientVector
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ builder = persistentListBuilderAdd(size, immutablePercentage)
+ }
+
+ @Benchmark
+ fun getByIndex(bh: Blackhole) {
+ for (i in 0 until size) {
+ bh.consume(builder.valAt(i))
+ }
+ }
+}
+
+
+
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ @Benchmark
+ fun addAndRemoveLast(): clojure.lang.ITransientVector {
+ val builder = persistentListBuilderAdd(size, immutablePercentage)
+ for (i in 0 until size) {
+ builder.pop()
+ }
+ return builder
+ }
+}
+
+
+@State(Scope.Thread)
+open class Set {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder = clojure.lang.PersistentVector.EMPTY.asTransient() as clojure.lang.ITransientVector
+ private var randomIndices = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ builder = persistentListBuilderAdd(size, immutablePercentage)
+ randomIndices = List(size) { it }.shuffled()
+ }
+
+ @Benchmark
+ fun setByIndex(): clojure.lang.ITransientVector {
+ for (i in 0 until size) {
+ builder.assocN(i, "another element")
+ }
+ return builder
+ }
+
+ @Benchmark
+ fun setByRandomIndex(): clojure.lang.ITransientVector {
+ for (i in 0 until size) {
+ builder.assocN(randomIndices[i], "another element")
+ }
+ return builder
+ }
+}
+
+
+private fun persistentListBuilderAdd(size: Int, immutablePercentage: Double): clojure.lang.ITransientVector {
+ val immutableSize = immutableSize(size, immutablePercentage)
+
+ var list = clojure.lang.PersistentVector.EMPTY
+ repeat(times = immutableSize) {
+ list = list.cons("another element")
+ }
+
+ val builder = list.asTransient() as clojure.lang.ITransientVector
+ repeat(times = size - immutableSize) {
+ builder.conj("some element")
+ }
+
+ return builder
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/cyclops/List.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/cyclops/List.kt
new file mode 100644
index 00000000..f1beecfb
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/cyclops/List.kt
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableList.cyclops
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Add {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Benchmark
+ fun addLast(): cyclops.data.Vector {
+ return persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun addLastAndIterate(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (e in list) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun addLastAndGet(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (i in 0 until size) {
+ bh.consume(list.get(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = cyclops.data.Vector.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun getByIndex(bh: Blackhole) {
+ for (i in 0 until size) {
+ bh.consume(persistentList.get(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = cyclops.data.Vector.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun firstToLast(bh: Blackhole) {
+ for (e in persistentList) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun lastToFirst(bh: Blackhole) {
+ val iterator = persistentList.reverse().iterator()
+
+ while (iterator.hasNext()) {
+ bh.consume(iterator.next())
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = cyclops.data.Vector.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun removeLast(): cyclops.data.Vector {
+ var list = persistentList
+ repeat(times = size) {
+ list = list.dropRight(1)
+ }
+ return list
+ }
+}
+
+
+@State(Scope.Thread)
+open class Set {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = cyclops.data.Vector.empty()
+ private var randomIndices = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ randomIndices = List(size) { it }.shuffled()
+ }
+
+ @Benchmark
+ fun setByIndex(): cyclops.data.Vector {
+ repeat(times = size) { index ->
+ persistentList = persistentList.updateAt(index, "another element")
+ }
+ return persistentList
+ }
+
+ @Benchmark
+ fun setByRandomIndex(): cyclops.data.Vector {
+ repeat(times = size) { index ->
+ persistentList = persistentList.updateAt(randomIndices[index], "another element")
+ }
+ return persistentList
+ }
+}
+
+
+private fun persistentListAdd(size: Int): cyclops.data.Vector {
+ var list = cyclops.data.Vector.empty()
+ repeat(times = size) {
+ list = list.plus("some element")
+ }
+ return list
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/kotlin/List.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/kotlin/List.kt
new file mode 100644
index 00000000..39a24526
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/kotlin/List.kt
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableList.kotlin
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Add {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Benchmark
+ fun addLast(): kotlinx.collections.immutable.PersistentList {
+ return persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun addLastAndIterate(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (e in list) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun addLastAndGet(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (i in 0 until size) {
+ bh.consume(list.get(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = kotlinx.collections.immutable.persistentListOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun getByIndex(bh: Blackhole) {
+ for (i in 0 until size) {
+ bh.consume(persistentList.get(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = kotlinx.collections.immutable.persistentListOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun firstToLast(bh: Blackhole) {
+ for (e in persistentList) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun lastToFirst(bh: Blackhole) {
+ val iterator = persistentList.listIterator(size)
+
+ while (iterator.hasPrevious()) {
+ bh.consume(iterator.previous())
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = kotlinx.collections.immutable.persistentListOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun removeLast(): kotlinx.collections.immutable.PersistentList {
+ var list = persistentList
+ repeat(times = size) {
+ list = list.removeAt(list.size - 1)
+ }
+ return list
+ }
+}
+
+
+@State(Scope.Thread)
+open class Set {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = kotlinx.collections.immutable.persistentListOf()
+ private var randomIndices = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ randomIndices = List(size) { it }.shuffled()
+ }
+
+ @Benchmark
+ fun setByIndex(): kotlinx.collections.immutable.PersistentList {
+ repeat(times = size) { index ->
+ persistentList = persistentList.set(index, "another element")
+ }
+ return persistentList
+ }
+
+ @Benchmark
+ fun setByRandomIndex(): kotlinx.collections.immutable.PersistentList {
+ repeat(times = size) { index ->
+ persistentList = persistentList.set(randomIndices[index], "another element")
+ }
+ return persistentList
+ }
+}
+
+
+private fun persistentListAdd(size: Int): kotlinx.collections.immutable.PersistentList {
+ var list = kotlinx.collections.immutable.persistentListOf()
+ repeat(times = size) {
+ list = list.add("some element")
+ }
+ return list
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/kotlin/builder/ListBuilder.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/kotlin/builder/ListBuilder.kt
new file mode 100644
index 00000000..67b4d60b
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/kotlin/builder/ListBuilder.kt
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableList.kotlin.builder
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Add {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ @Benchmark
+ fun addLast(): kotlinx.collections.immutable.PersistentList.Builder {
+ return persistentListBuilderAdd(size, immutablePercentage)
+ }
+
+ @Benchmark
+ fun addLastAndGet(bh: Blackhole) {
+ val builder = persistentListBuilderAdd(size, immutablePercentage)
+ for (i in 0 until size) {
+ bh.consume(builder.get(i))
+ }
+ }
+
+
+ @Benchmark
+ fun addLastAndIterate(bh: Blackhole) {
+ val builder = persistentListBuilderAdd(size, immutablePercentage)
+ for (e in builder) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder: kotlinx.collections.immutable.PersistentList.Builder = kotlinx.collections.immutable.persistentListOf().builder()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ builder = persistentListBuilderAdd(size, immutablePercentage)
+ }
+
+ @Benchmark
+ fun getByIndex(bh: Blackhole) {
+ for (i in 0 until size) {
+ bh.consume(builder.get(i))
+ }
+ }
+}
+
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder = kotlinx.collections.immutable.persistentListOf().builder()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ builder = persistentListBuilderAdd(size, immutablePercentage)
+ }
+
+ @Benchmark
+ fun firstToLast(bh: Blackhole) {
+ for (e in builder) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun lastToFirst(bh: Blackhole) {
+ val iterator = builder.listIterator(size)
+
+ while (iterator.hasPrevious()) {
+ bh.consume(iterator.previous())
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ @Benchmark
+ fun addAndRemoveLast(): kotlinx.collections.immutable.PersistentList.Builder {
+ val builder = persistentListBuilderAdd(size, immutablePercentage)
+ for (i in 0 until size) {
+ builder.removeAt(builder.size - 1)
+ }
+ return builder
+ }
+}
+
+
+@State(Scope.Thread)
+open class Set {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder = kotlinx.collections.immutable.persistentListOf().builder()
+ private var randomIndices = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ builder = persistentListBuilderAdd(size, immutablePercentage)
+ randomIndices = List(size) { it }.shuffled()
+ }
+
+ @Benchmark
+ fun setByIndex(): kotlinx.collections.immutable.PersistentList.Builder {
+ for (i in 0 until size) {
+ builder.set(i, "another element")
+ }
+ return builder
+ }
+
+ @Benchmark
+ fun setByRandomIndex(): kotlinx.collections.immutable.PersistentList.Builder {
+ for (i in 0 until size) {
+ builder.set(randomIndices[i], "another element")
+ }
+ return builder
+ }
+}
+
+
+private fun persistentListBuilderAdd(size: Int, immutablePercentage: Double): kotlinx.collections.immutable.PersistentList.Builder {
+ val immutableSize = immutableSize(size, immutablePercentage)
+
+ var list = kotlinx.collections.immutable.persistentListOf()
+ repeat(times = immutableSize) {
+ list = list.add("another element")
+ }
+
+ val builder = list.builder()
+ repeat(times = size - immutableSize) {
+ builder.add("some element")
+ }
+
+ return builder
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/paguro/List.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/paguro/List.kt
new file mode 100644
index 00000000..91964acb
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/paguro/List.kt
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableList.paguro
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Add {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Benchmark
+ fun addLast(): org.organicdesign.fp.collections.RrbTree.ImRrbt {
+ return persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun addLastAndIterate(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (e in list) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun addLastAndGet(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (i in 0 until size) {
+ bh.consume(list.get(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = org.organicdesign.fp.collections.RrbTree.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun getByIndex(bh: Blackhole) {
+ for (i in 0 until size) {
+ bh.consume(persistentList.get(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = org.organicdesign.fp.collections.RrbTree.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun firstToLast(bh: Blackhole) {
+ for (e in persistentList) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun lastToFirst(bh: Blackhole) {
+ val iterator = persistentList.listIterator(size)
+
+ while (iterator.hasPrevious()) {
+ bh.consume(iterator.previous())
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = org.organicdesign.fp.collections.RrbTree.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun removeLast(): org.organicdesign.fp.collections.RrbTree.ImRrbt {
+ var list = persistentList
+ repeat(times = size) {
+ list = list.without(list.size - 1)
+ }
+ return list
+ }
+}
+
+
+@State(Scope.Thread)
+open class Set {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = org.organicdesign.fp.collections.RrbTree.empty()
+ private var randomIndices = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ randomIndices = List(size) { it }.shuffled()
+ }
+
+ @Benchmark
+ fun setByIndex(): org.organicdesign.fp.collections.RrbTree.ImRrbt {
+ repeat(times = size) { index ->
+ persistentList = persistentList.replace(index, "another element")
+ }
+ return persistentList
+ }
+
+ @Benchmark
+ fun setByRandomIndex(): org.organicdesign.fp.collections.RrbTree.ImRrbt {
+ repeat(times = size) { index ->
+ persistentList = persistentList.replace(randomIndices[index], "another element")
+ }
+ return persistentList
+ }
+}
+
+
+private fun persistentListAdd(size: Int): org.organicdesign.fp.collections.RrbTree.ImRrbt {
+ var list = org.organicdesign.fp.collections.RrbTree.empty()
+ repeat(times = size) {
+ list = list.append("some element")
+ }
+ return list
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/paguro/builder/ListBuilder.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/paguro/builder/ListBuilder.kt
new file mode 100644
index 00000000..8d303afd
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/paguro/builder/ListBuilder.kt
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableList.paguro.builder
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Add {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ @Benchmark
+ fun addLast(): org.organicdesign.fp.collections.RrbTree.MutableRrbt {
+ return persistentListBuilderAdd(size, immutablePercentage)
+ }
+
+ @Benchmark
+ fun addLastAndGet(bh: Blackhole) {
+ val builder = persistentListBuilderAdd(size, immutablePercentage)
+ for (i in 0 until size) {
+ bh.consume(builder.get(i))
+ }
+ }
+
+
+ @Benchmark
+ fun addLastAndIterate(bh: Blackhole) {
+ val builder = persistentListBuilderAdd(size, immutablePercentage)
+ for (e in builder) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder: org.organicdesign.fp.collections.RrbTree.MutableRrbt = org.organicdesign.fp.collections.RrbTree.emptyMutable()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ builder = persistentListBuilderAdd(size, immutablePercentage)
+ }
+
+ @Benchmark
+ fun getByIndex(bh: Blackhole) {
+ for (i in 0 until size) {
+ bh.consume(builder.get(i))
+ }
+ }
+}
+
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder = org.organicdesign.fp.collections.RrbTree.emptyMutable()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ builder = persistentListBuilderAdd(size, immutablePercentage)
+ }
+
+ @Benchmark
+ fun firstToLast(bh: Blackhole) {
+ for (e in builder) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun lastToFirst(bh: Blackhole) {
+ val iterator = builder.listIterator(size)
+
+ while (iterator.hasPrevious()) {
+ bh.consume(iterator.previous())
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ @Benchmark
+ fun addAndRemoveLast(): org.organicdesign.fp.collections.RrbTree.MutableRrbt {
+ val builder = persistentListBuilderAdd(size, immutablePercentage)
+ for (i in 0 until size) {
+ builder.without(builder.size - 1)
+ }
+ return builder
+ }
+}
+
+
+@State(Scope.Thread)
+open class Set {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder = org.organicdesign.fp.collections.RrbTree.emptyMutable()
+ private var randomIndices = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ builder = persistentListBuilderAdd(size, immutablePercentage)
+ randomIndices = List(size) { it }.shuffled()
+ }
+
+ @Benchmark
+ fun setByIndex(): org.organicdesign.fp.collections.RrbTree.MutableRrbt {
+ for (i in 0 until size) {
+ builder.replace(i, "another element")
+ }
+ return builder
+ }
+
+ @Benchmark
+ fun setByRandomIndex(): org.organicdesign.fp.collections.RrbTree.MutableRrbt {
+ for (i in 0 until size) {
+ builder.replace(randomIndices[i], "another element")
+ }
+ return builder
+ }
+}
+
+
+private fun persistentListBuilderAdd(size: Int, immutablePercentage: Double): org.organicdesign.fp.collections.RrbTree.MutableRrbt {
+ val immutableSize = immutableSize(size, immutablePercentage)
+
+ var list = org.organicdesign.fp.collections.RrbTree.empty()
+ repeat(times = immutableSize) {
+ list = list.append("another element")
+ }
+
+ val builder = list.mutable()
+ repeat(times = size - immutableSize) {
+ builder.append("some element")
+ }
+
+ return builder
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/scala/List.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/scala/List.kt
new file mode 100644
index 00000000..a475e7bc
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/scala/List.kt
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableList.scala
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Add {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Benchmark
+ fun addLast(): scala.collection.immutable.Vector {
+ return persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun addLastAndIterate(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (e in list) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun addLastAndGet(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (i in 0 until size) {
+ bh.consume(list.apply(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = scala.collection.immutable.`Vector$`.`MODULE$`.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun getByIndex(bh: Blackhole) {
+ for (i in 0 until size) {
+ bh.consume(persistentList.apply(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = scala.collection.immutable.`Vector$`.`MODULE$`.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun firstToLast(bh: Blackhole) {
+ for (e in persistentList) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun lastToFirst(bh: Blackhole) {
+ val iterator = persistentList.reverseIterator()
+
+ while (iterator.hasNext()) {
+ bh.consume(iterator.next())
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = scala.collection.immutable.`Vector$`.`MODULE$`.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun removeLast(): scala.collection.immutable.Vector {
+ var list = persistentList
+ repeat(times = size) {
+ list = list.dropRight(1)
+ }
+ return list
+ }
+}
+
+
+@State(Scope.Thread)
+open class Set {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = scala.collection.immutable.`Vector$`.`MODULE$`.empty()
+ private var randomIndices = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ randomIndices = List(size) { it }.shuffled()
+ }
+
+ @Benchmark
+ fun setByIndex(): scala.collection.immutable.Vector {
+ repeat(times = size) { index ->
+ persistentList = persistentList.updateAt(index, "another element")
+ }
+ return persistentList
+ }
+
+ @Benchmark
+ fun setByRandomIndex(): scala.collection.immutable.Vector {
+ repeat(times = size) { index ->
+ persistentList = persistentList.updateAt(randomIndices[index], "another element")
+ }
+ return persistentList
+ }
+}
+
+
+private fun persistentListAdd(size: Int): scala.collection.immutable.Vector {
+ var list = scala.collection.immutable.`Vector$`.`MODULE$`.empty()
+ repeat(times = size) {
+ list = list.appended("some element") as scala.collection.immutable.Vector
+ }
+ return list
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/vavr/List.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/vavr/List.kt
new file mode 100644
index 00000000..414364b0
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableList/vavr/List.kt
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableList.vavr
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Add {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Benchmark
+ fun addLast(): io.vavr.collection.Vector {
+ return persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun addLastAndIterate(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (e in list) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun addLastAndGet(bh: Blackhole) {
+ val list = persistentListAdd(size)
+ for (i in 0 until size) {
+ bh.consume(list.apply(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = io.vavr.collection.Vector.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun getByIndex(bh: Blackhole) {
+ for (i in 0 until size) {
+ bh.consume(persistentList.apply(i))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = io.vavr.collection.Vector.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun firstToLast(bh: Blackhole) {
+ for (e in persistentList) {
+ bh.consume(e)
+ }
+ }
+
+ @Benchmark
+ fun lastToFirst(bh: Blackhole) {
+ val iterator = persistentList.reverseIterator()
+
+ while (iterator.hasNext()) {
+ bh.consume(iterator.next())
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = io.vavr.collection.Vector.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ }
+
+ @Benchmark
+ fun removeLast(): io.vavr.collection.Vector {
+ var list = persistentList
+ repeat(times = size) {
+ list = list.dropRight(1)
+ }
+ return list
+ }
+}
+
+
+@State(Scope.Thread)
+open class Set {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ private var persistentList = io.vavr.collection.Vector.empty()
+ private var randomIndices = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentList = persistentListAdd(size)
+ randomIndices = List(size) { it }.shuffled()
+ }
+
+ @Benchmark
+ fun setByIndex(): io.vavr.collection.Vector {
+ repeat(times = size) { index ->
+ persistentList = persistentList.update(index, "another element")
+ }
+ return persistentList
+ }
+
+ @Benchmark
+ fun setByRandomIndex(): io.vavr.collection.Vector {
+ repeat(times = size) { index ->
+ persistentList = persistentList.update(randomIndices[index], "another element")
+ }
+ return persistentList
+ }
+}
+
+
+private fun persistentListAdd(size: Int): io.vavr.collection.Vector {
+ var list = io.vavr.collection.Vector.empty()
+ repeat(times = size) {
+ list = list.append("some element")
+ }
+ return list
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/capsule/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/capsule/Map.kt
new file mode 100644
index 00000000..bb70955a
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/capsule/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.capsule
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = io.usethesource.capsule.core.PersistentTrieMap.of()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = io.usethesource.capsule.core.PersistentTrieMap.of()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): io.usethesource.capsule.Map.Immutable {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = io.usethesource.capsule.core.PersistentTrieMap.of()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): io.usethesource.capsule.Map.Immutable {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.__remove(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): io.usethesource.capsule.Map.Immutable {
+ var map = io.usethesource.capsule.core.PersistentTrieMap.of()
+ for (key in keys) {
+ map = map.__put(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/capsule/builder/MapBuilder.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/capsule/builder/MapBuilder.kt
new file mode 100644
index 00000000..e4ba081c
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/capsule/builder/MapBuilder.kt
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.capsule.builder
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var builder = io.usethesource.capsule.core.PersistentTrieMap.of().asTransient()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ builder = persistentMapBuilderPut(keys, immutablePercentage)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(builder.get(keys[index]))
+ }
+ }
+}
+
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder = io.usethesource.capsule.core.PersistentTrieMap.of().asTransient()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ val keys = generateKeys(hashCodeType, size)
+ builder = persistentMapBuilderPut(keys, immutablePercentage)
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in builder.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in builder.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in builder) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): io.usethesource.capsule.Map.Transient {
+ return persistentMapBuilderPut(keys, immutablePercentage)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ bh.consume(builder.get(keys[index]))
+ }
+ }
+
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ for (key in builder.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var keysToRemove = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+
+ keysToRemove = if (hashCodeType == NON_EXISTING_HASH_CODE) {
+ generateKeys(hashCodeType, size)
+ } else {
+ keys
+ }
+ }
+
+ @Benchmark
+ fun putAndRemove(): io.usethesource.capsule.Map.Transient {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ builder.remove(keysToRemove[index])
+ }
+ return builder
+ }
+}
+
+
+private fun persistentMapBuilderPut(
+ keys: List,
+ immutablePercentage: Double
+): io.usethesource.capsule.Map.Transient {
+ val immutableSize = immutableSize(keys.size, immutablePercentage)
+
+ var map = io.usethesource.capsule.core.PersistentTrieMap.of()
+ for (index in 0 until immutableSize) {
+ map = map.__put(keys[index], "some element")
+ }
+
+ val builder = map.asTransient()
+ for (index in immutableSize until keys.size) {
+ builder.put(keys[index], "some element")
+ }
+
+ return builder
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/clojure/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/clojure/Map.kt
new file mode 100644
index 00000000..21adb693
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/clojure/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.clojure
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = clojure.lang.PersistentHashMap.EMPTY
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.valAt(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = clojure.lang.PersistentHashMap.EMPTY
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): clojure.lang.PersistentHashMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.valAt(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = clojure.lang.PersistentHashMap.EMPTY
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): clojure.lang.PersistentHashMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.without(keys[index]) as clojure.lang.PersistentHashMap
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): clojure.lang.PersistentHashMap {
+ var map = clojure.lang.PersistentHashMap.EMPTY
+ for (key in keys) {
+ map = map.assoc(key, "some element") as clojure.lang.PersistentHashMap
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/clojure/builder/MapBuilder.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/clojure/builder/MapBuilder.kt
new file mode 100644
index 00000000..61c80c21
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/clojure/builder/MapBuilder.kt
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.clojure.builder
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var builder = clojure.lang.PersistentHashMap.EMPTY.asTransient() as clojure.lang.ATransientMap
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ builder = persistentMapBuilderPut(keys, immutablePercentage)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(builder.valAt(keys[index]))
+ }
+ }
+}
+
+
+
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): clojure.lang.ATransientMap {
+ return persistentMapBuilderPut(keys, immutablePercentage)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ bh.consume(builder.valAt(keys[index]))
+ }
+ }
+
+
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var keysToRemove = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+
+ keysToRemove = if (hashCodeType == NON_EXISTING_HASH_CODE) {
+ generateKeys(hashCodeType, size)
+ } else {
+ keys
+ }
+ }
+
+ @Benchmark
+ fun putAndRemove(): clojure.lang.ATransientMap {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ builder.without(keysToRemove[index])
+ }
+ return builder
+ }
+}
+
+
+private fun persistentMapBuilderPut(
+ keys: List,
+ immutablePercentage: Double
+): clojure.lang.ATransientMap {
+ val immutableSize = immutableSize(keys.size, immutablePercentage)
+
+ var map = clojure.lang.PersistentHashMap.EMPTY as clojure.lang.IPersistentMap
+ for (index in 0 until immutableSize) {
+ map = map.assoc(keys[index], "some element")
+ }
+
+ val builder = (map as clojure.lang.PersistentHashMap).asTransient() as clojure.lang.ATransientMap
+ for (index in immutableSize until keys.size) {
+ builder.assoc(keys[index], "some element")
+ }
+
+ return builder
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/clojureSorted/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/clojureSorted/Map.kt
new file mode 100644
index 00000000..6a515b43
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/clojureSorted/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.clojureSorted
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = clojure.lang.PersistentTreeMap.EMPTY
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.valAt(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = clojure.lang.PersistentTreeMap.EMPTY
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): clojure.lang.PersistentTreeMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.valAt(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = clojure.lang.PersistentTreeMap.EMPTY
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): clojure.lang.PersistentTreeMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.without(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): clojure.lang.PersistentTreeMap {
+ var map = clojure.lang.PersistentTreeMap.EMPTY
+ for (key in keys) {
+ map = map.assoc(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/cyclops/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/cyclops/Map.kt
new file mode 100644
index 00000000..b4c9b08a
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/cyclops/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.cyclops
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = cyclops.data.HashMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = cyclops.data.HashMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys()) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values()) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): cyclops.data.HashMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys()) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = cyclops.data.HashMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): cyclops.data.HashMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.remove(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): cyclops.data.HashMap {
+ var map = cyclops.data.HashMap.empty()
+ for (key in keys) {
+ map = map.put(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/cyclopsOrdered/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/cyclopsOrdered/Map.kt
new file mode 100644
index 00000000..5a8bbd79
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/cyclopsOrdered/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.cyclopsOrdered
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = cyclops.data.LinkedMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = cyclops.data.LinkedMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys()) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values()) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): cyclops.data.LinkedMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys()) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = cyclops.data.LinkedMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): cyclops.data.LinkedMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.remove(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): cyclops.data.LinkedMap {
+ var map = cyclops.data.LinkedMap.empty()
+ for (key in keys) {
+ map = map.put(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/cyclopsTrie/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/cyclopsTrie/Map.kt
new file mode 100644
index 00000000..9c665391
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/cyclopsTrie/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.cyclopsTrie
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = cyclops.data.TrieMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = cyclops.data.TrieMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys()) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values()) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): cyclops.data.TrieMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys()) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = cyclops.data.TrieMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): cyclops.data.TrieMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.remove(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): cyclops.data.TrieMap {
+ var map = cyclops.data.TrieMap.empty()
+ for (key in keys) {
+ map = map.put(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlin/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlin/Map.kt
new file mode 100644
index 00000000..a73a2e12
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlin/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.kotlin
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = kotlinx.collections.immutable.persistentHashMapOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = kotlinx.collections.immutable.persistentHashMapOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): kotlinx.collections.immutable.PersistentMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = kotlinx.collections.immutable.persistentHashMapOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): kotlinx.collections.immutable.PersistentMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.remove(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): kotlinx.collections.immutable.PersistentMap {
+ var map = kotlinx.collections.immutable.persistentHashMapOf()
+ for (key in keys) {
+ map = map.put(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlin/builder/MapBuilder.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlin/builder/MapBuilder.kt
new file mode 100644
index 00000000..3ebea2fc
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlin/builder/MapBuilder.kt
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.kotlin.builder
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var builder = kotlinx.collections.immutable.persistentHashMapOf().builder()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ builder = persistentMapBuilderPut(keys, immutablePercentage)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(builder.get(keys[index]))
+ }
+ }
+}
+
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder = kotlinx.collections.immutable.persistentHashMapOf().builder()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ val keys = generateKeys(hashCodeType, size)
+ builder = persistentMapBuilderPut(keys, immutablePercentage)
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in builder.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in builder.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in builder) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): kotlinx.collections.immutable.PersistentMap.Builder {
+ return persistentMapBuilderPut(keys, immutablePercentage)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ bh.consume(builder.get(keys[index]))
+ }
+ }
+
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ for (key in builder.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var keysToRemove = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+
+ keysToRemove = if (hashCodeType == NON_EXISTING_HASH_CODE) {
+ generateKeys(hashCodeType, size)
+ } else {
+ keys
+ }
+ }
+
+ @Benchmark
+ fun putAndRemove(): kotlinx.collections.immutable.PersistentMap.Builder {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ builder.remove(keysToRemove[index])
+ }
+ return builder
+ }
+}
+
+
+private fun persistentMapBuilderPut(
+ keys: List,
+ immutablePercentage: Double
+): kotlinx.collections.immutable.PersistentMap.Builder {
+ val immutableSize = immutableSize(keys.size, immutablePercentage)
+
+ var map = kotlinx.collections.immutable.persistentHashMapOf()
+ for (index in 0 until immutableSize) {
+ map = map.put(keys[index], "some element")
+ }
+
+ val builder = map.builder()
+ for (index in immutableSize until keys.size) {
+ builder.put(keys[index], "some element")
+ }
+
+ return builder
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlinOrdered/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlinOrdered/Map.kt
new file mode 100644
index 00000000..006ede4f
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlinOrdered/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.kotlinOrdered
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = kotlinx.collections.immutable.persistentMapOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = kotlinx.collections.immutable.persistentMapOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): kotlinx.collections.immutable.PersistentMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = kotlinx.collections.immutable.persistentMapOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): kotlinx.collections.immutable.PersistentMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.remove(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): kotlinx.collections.immutable.PersistentMap {
+ var map = kotlinx.collections.immutable.persistentMapOf()
+ for (key in keys) {
+ map = map.put(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlinOrdered/builder/MapBuilder.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlinOrdered/builder/MapBuilder.kt
new file mode 100644
index 00000000..3f210703
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/kotlinOrdered/builder/MapBuilder.kt
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.kotlinOrdered.builder
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var builder = kotlinx.collections.immutable.persistentMapOf().builder()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ builder = persistentMapBuilderPut(keys, immutablePercentage)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(builder.get(keys[index]))
+ }
+ }
+}
+
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder = kotlinx.collections.immutable.persistentMapOf().builder()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ val keys = generateKeys(hashCodeType, size)
+ builder = persistentMapBuilderPut(keys, immutablePercentage)
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in builder.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in builder.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in builder) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): kotlinx.collections.immutable.PersistentMap.Builder {
+ return persistentMapBuilderPut(keys, immutablePercentage)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ bh.consume(builder.get(keys[index]))
+ }
+ }
+
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ for (key in builder.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var keysToRemove = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+
+ keysToRemove = if (hashCodeType == NON_EXISTING_HASH_CODE) {
+ generateKeys(hashCodeType, size)
+ } else {
+ keys
+ }
+ }
+
+ @Benchmark
+ fun putAndRemove(): kotlinx.collections.immutable.PersistentMap.Builder {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ builder.remove(keysToRemove[index])
+ }
+ return builder
+ }
+}
+
+
+private fun persistentMapBuilderPut(
+ keys: List,
+ immutablePercentage: Double
+): kotlinx.collections.immutable.PersistentMap.Builder {
+ val immutableSize = immutableSize(keys.size, immutablePercentage)
+
+ var map = kotlinx.collections.immutable.persistentMapOf()
+ for (index in 0 until immutableSize) {
+ map = map.put(keys[index], "some element")
+ }
+
+ val builder = map.builder()
+ for (index in immutableSize until keys.size) {
+ builder.put(keys[index], "some element")
+ }
+
+ return builder
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/paguro/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/paguro/Map.kt
new file mode 100644
index 00000000..400da089
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/paguro/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.paguro
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = org.organicdesign.fp.collections.PersistentHashMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = org.organicdesign.fp.collections.PersistentHashMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): org.organicdesign.fp.collections.PersistentHashMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = org.organicdesign.fp.collections.PersistentHashMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): org.organicdesign.fp.collections.PersistentHashMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.without(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): org.organicdesign.fp.collections.PersistentHashMap {
+ var map = org.organicdesign.fp.collections.PersistentHashMap.empty()
+ for (key in keys) {
+ map = map.assoc(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/paguro/builder/MapBuilder.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/paguro/builder/MapBuilder.kt
new file mode 100644
index 00000000..5034aacb
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/paguro/builder/MapBuilder.kt
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.paguro.builder
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var builder = org.organicdesign.fp.collections.PersistentHashMap.emptyMutable()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ builder = persistentMapBuilderPut(keys, immutablePercentage)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(builder.get(keys[index]))
+ }
+ }
+}
+
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var builder = org.organicdesign.fp.collections.PersistentHashMap.emptyMutable()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ val keys = generateKeys(hashCodeType, size)
+ builder = persistentMapBuilderPut(keys, immutablePercentage)
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in builder.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in builder.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in builder) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): org.organicdesign.fp.collections.PersistentHashMap.MutableHashMap {
+ return persistentMapBuilderPut(keys, immutablePercentage)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ bh.consume(builder.get(keys[index]))
+ }
+ }
+
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ for (key in builder.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ @Param("0.0", "50.0")
+ var immutablePercentage: Double = 0.0
+
+ private var keys = listOf()
+ private var keysToRemove = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+
+ keysToRemove = if (hashCodeType == NON_EXISTING_HASH_CODE) {
+ generateKeys(hashCodeType, size)
+ } else {
+ keys
+ }
+ }
+
+ @Benchmark
+ fun putAndRemove(): org.organicdesign.fp.collections.PersistentHashMap.MutableHashMap {
+ val builder = persistentMapBuilderPut(keys, immutablePercentage)
+ repeat(times = size) { index ->
+ builder.without(keysToRemove[index])
+ }
+ return builder
+ }
+}
+
+
+private fun persistentMapBuilderPut(
+ keys: List,
+ immutablePercentage: Double
+): org.organicdesign.fp.collections.PersistentHashMap.MutableHashMap {
+ val immutableSize = immutableSize(keys.size, immutablePercentage)
+
+ var map = org.organicdesign.fp.collections.PersistentHashMap.empty()
+ for (index in 0 until immutableSize) {
+ map = map.assoc(keys[index], "some element")
+ }
+
+ val builder = map.mutable()
+ for (index in immutableSize until keys.size) {
+ builder.assoc(keys[index], "some element")
+ }
+
+ return builder
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/paguroSorted/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/paguroSorted/Map.kt
new file mode 100644
index 00000000..610935ea
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/paguroSorted/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.paguroSorted
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = org.organicdesign.fp.collections.PersistentTreeMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = org.organicdesign.fp.collections.PersistentTreeMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): org.organicdesign.fp.collections.PersistentTreeMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = org.organicdesign.fp.collections.PersistentTreeMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): org.organicdesign.fp.collections.PersistentTreeMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.without(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): org.organicdesign.fp.collections.PersistentTreeMap {
+ var map = org.organicdesign.fp.collections.PersistentTreeMap.empty()
+ for (key in keys) {
+ map = map.assoc(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/scala/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/scala/Map.kt
new file mode 100644
index 00000000..cde2153e
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/scala/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.scala
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = scala.collection.immutable.`HashMap$`.`MODULE$`.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = scala.collection.immutable.`HashMap$`.`MODULE$`.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys()) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values()) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): scala.collection.immutable.HashMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys()) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = scala.collection.immutable.`HashMap$`.`MODULE$`.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): scala.collection.immutable.HashMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.removed(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): scala.collection.immutable.HashMap {
+ var map = scala.collection.immutable.`HashMap$`.`MODULE$`.empty()
+ for (key in keys) {
+ map = map.updated(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/scalaSorted/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/scalaSorted/Map.kt
new file mode 100644
index 00000000..be18c193
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/scalaSorted/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.scalaSorted
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = scala.collection.immutable.`TreeMap$`.`MODULE$`.empty(scala.math.Ordering.comparatorToOrdering(Comparator.naturalOrder()))
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = scala.collection.immutable.`TreeMap$`.`MODULE$`.empty(scala.math.Ordering.comparatorToOrdering(Comparator.naturalOrder()))
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ persistentMap = persistentMapPut(generateKeys(hashCodeType, size))
+ }
+
+ @Benchmark
+ fun iterateKeys(bh: Blackhole) {
+ for (k in persistentMap.keys()) {
+ bh.consume(k)
+ }
+ }
+
+ @Benchmark
+ fun iterateValues(bh: Blackhole) {
+ for (v in persistentMap.values()) {
+ bh.consume(v)
+ }
+ }
+
+ @Benchmark
+ fun iterateEntries(bh: Blackhole) {
+ for (e in persistentMap) {
+ bh.consume(e)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Put {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun put(): scala.collection.immutable.TreeMap {
+ return persistentMapPut(keys)
+ }
+
+ @Benchmark
+ fun putAndGet(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ repeat(times = size) { index ->
+ bh.consume(map.get(keys[index]))
+ }
+ }
+
+ @Benchmark
+ fun putAndIterateKeys(bh: Blackhole) {
+ val map = persistentMapPut(keys)
+ for (key in map.keys()) {
+ bh.consume(key)
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Remove {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = scala.collection.immutable.`TreeMap$`.`MODULE$`.empty(scala.math.Ordering.comparatorToOrdering(Comparator.naturalOrder()))
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+ }
+
+ @Benchmark
+ fun remove(): scala.collection.immutable.TreeMap {
+ var map = persistentMap
+ repeat(times = size) { index ->
+ map = map.removed(keys[index])
+ }
+ return map
+ }
+}
+
+
+private fun persistentMapPut(keys: List): scala.collection.immutable.TreeMap {
+ var map = scala.collection.immutable.`TreeMap$`.`MODULE$`.empty(scala.math.Ordering.comparatorToOrdering(Comparator.naturalOrder()))
+ for (key in keys) {
+ map = map.updated(key, "some element")
+ }
+ return map
+}
diff --git a/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/vavr/Map.kt b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/vavr/Map.kt
new file mode 100644
index 00000000..3ae150b4
--- /dev/null
+++ b/benchmarks-libraries/src/jmh/java/benchmarks/immutableMap/vavr/Map.kt
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-2019 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Auto-generated file. DO NOT EDIT!
+
+package benchmarks.immutableMap.vavr
+
+import org.openjdk.jmh.annotations.*
+import java.util.concurrent.TimeUnit
+import org.openjdk.jmh.infra.Blackhole
+import benchmarks.*
+
+@State(Scope.Thread)
+open class Get {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE, NON_EXISTING_HASH_CODE)
+ var hashCodeType = ""
+
+ private var keys = listOf()
+ private var persistentMap = io.vavr.collection.HashMap.empty()
+
+ @Setup(Level.Trial)
+ fun prepare() {
+ keys = generateKeys(hashCodeType, size)
+ persistentMap = persistentMapPut(keys)
+
+ if (hashCodeType == NON_EXISTING_HASH_CODE)
+ keys = generateKeys(hashCodeType, size)
+
+ }
+
+ @Benchmark
+ fun get(bh: Blackhole) {
+ repeat(times = size) { index ->
+ bh.consume(persistentMap.get(keys[index]))
+ }
+ }
+}
+
+
+@State(Scope.Thread)
+open class Iterate {
+ @Param("10000", "100000")
+ var size: Int = 0
+
+ @Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
+ var hashCodeType = ""
+
+ private var persistentMap = io.vavr.collection.HashMap.empty