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