Skip to content

Commit f5f852b

Browse files
Abduqodiri Qurbonzodaqurbonzoda
authored andcommitted
Add PersistentMap.putAll benchmark
1 parent 5fa1aad commit f5f852b

File tree

1 file changed

+52
-0
lines changed
  • benchmarks/commonMain/src/benchmarks/immutableMap

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2016-2021 JetBrains s.r.o.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package benchmarks.immutableMap
7+
8+
import benchmarks.*
9+
import kotlinx.collections.immutable.PersistentMap
10+
import kotlinx.benchmark.*
11+
import kotlinx.collections.immutable.persistentMapOf
12+
13+
@State(Scope.Benchmark)
14+
open class PutAll {
15+
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000)
16+
var size: Int = 0
17+
18+
@Param(HASH_IMPL, ORDERED_IMPL)
19+
var implementation = ""
20+
21+
@Param(ASCENDING_HASH_CODE, RANDOM_HASH_CODE, COLLISION_HASH_CODE)
22+
var hashCodeType = ""
23+
24+
private var lhs = persistentMapOf<IntWrapper, String>()
25+
private var lhsSmall = persistentMapOf<IntWrapper, String>()
26+
private var rhs = persistentMapOf<IntWrapper, String>()
27+
private var rhsSmall = persistentMapOf<IntWrapper, String>()
28+
29+
@Setup
30+
fun prepare() {
31+
val keys = generateKeys(hashCodeType, 2 * size)
32+
lhs = persistentMapPut(implementation, keys.take(size))
33+
lhsSmall = persistentMapPut(implementation, keys.take((size / 1000) + 1))
34+
rhs = persistentMapPut(implementation, keys.takeLast(size))
35+
rhsSmall = persistentMapPut(implementation, keys.takeLast((size / 1000) + 1))
36+
}
37+
38+
@Benchmark
39+
fun putAllEqualSize(): PersistentMap<IntWrapper, String> {
40+
return lhs.putAll(rhs)
41+
}
42+
43+
@Benchmark
44+
fun putAllSmallIntoLarge(): PersistentMap<IntWrapper, String> {
45+
return lhs.putAll(rhsSmall)
46+
}
47+
48+
@Benchmark
49+
fun putAllLargeIntoSmall(): PersistentMap<IntWrapper, String> {
50+
return lhsSmall.putAll(rhs)
51+
}
52+
}

0 commit comments

Comments
 (0)