Skip to content

Commit 9d17362

Browse files
author
Abduqodiri Qurbonzoda
committed
Comment benchmark methods
1 parent 83f67fa commit 9d17362

File tree

26 files changed

+276
-0
lines changed

26 files changed

+276
-0
lines changed

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Add.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,23 @@ open class Add {
2626
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
2727
var size: Int = 0
2828

29+
/**
30+
* Adds [size] elements to an empty persistent list.
31+
*
32+
* Expected time: nearly constant.
33+
* Expected memory: for size in 1..32 - O(size), nearly constant otherwise.
34+
*/
2935
@Benchmark
3036
fun addLast(): ImmutableList<String> {
3137
return persistentListAdd(size)
3238
}
3339

40+
/**
41+
* Adds [size] elements to an empty persistent list and then iterates all elements from first to last.
42+
*
43+
* Expected time: [addLast] + [Iterate.firstToLast]
44+
* Expected memory: [addLast] + [Iterate.firstToLast]
45+
*/
3446
@Benchmark
3547
fun addLastAndIterate(bh: Blackhole) {
3648
val list = persistentListAdd(size)
@@ -39,6 +51,12 @@ open class Add {
3951
}
4052
}
4153

54+
/**
55+
* Adds [size] elements to an empty persistent list and then gets all elements by index from first to last.
56+
*
57+
* Expected time: [addLast] + [Get.getByIndex]
58+
* Expected memory: [addLast] + [Get.getByIndex]
59+
*/
4260
@Benchmark
4361
fun addLastAndGet(bh: Blackhole) {
4462
val list = persistentListAdd(size)

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Get.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ open class Get {
3434
persistentList = persistentListAdd(size)
3535
}
3636

37+
/**
38+
* Gets every element by index starting from first to last.
39+
*
40+
* Expected time: logarithmic
41+
* Expected memory: none
42+
*/
3743
@Benchmark
3844
fun getByIndex(bh: Blackhole) {
3945
for (i in 0 until persistentList.size) {

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Iterate.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,25 @@ open class Iterate {
3434
persistentList = persistentListAdd(size)
3535
}
3636

37+
/**
38+
* Iterates every element starting from first to last.
39+
*
40+
* Expected time: nearly constant
41+
* Expected memory: none once iterator created
42+
*/
3743
@Benchmark
3844
fun firstToLast(bh: Blackhole) {
3945
for (e in persistentList) {
4046
bh.consume(e)
4147
}
4248
}
4349

50+
/**
51+
* Iterates every element starting from last to first.
52+
*
53+
* Expected time: nearly constant
54+
* Expected memory: none once iterator created
55+
*/
4456
@Benchmark
4557
fun lastToFirst(bh: Blackhole) {
4658
val iterator = persistentList.listIterator(size)

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Remove.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ open class Remove {
3434
persistentList = persistentListAdd(size)
3535
}
3636

37+
/**
38+
* Removes all elements by index starting from last to first.
39+
*
40+
* Expected time: nearly constant.
41+
* Expected memory: for size in 1..32 - O(size), nearly constant otherwise.
42+
*/
3743
@Benchmark
3844
fun removeLast(): ImmutableList<String> {
3945
var list = persistentList

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Set.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ open class Set {
3636
randomIndices = List(size) { it }.shuffled()
3737
}
3838

39+
/**
40+
* Updates each element by index starting from first to last.
41+
*
42+
* Expected time: logarithmic
43+
* Expected memory: logarithmic
44+
*/
3945
@Benchmark
4046
fun setByIndex(): ImmutableList<String> {
4147
repeat(times = size) { index ->
@@ -44,6 +50,12 @@ open class Set {
4450
return persistentList
4551
}
4652

53+
/**
54+
* Updates each element by index randomly.
55+
*
56+
* Expected time: logarithmic
57+
* Expected memory: logarithmic
58+
*/
4759
@Benchmark
4860
fun setByRandomIndex(): ImmutableList<String> {
4961
repeat(times = size) { index ->

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/builder/Add.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,23 @@ open class Add {
2929
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
3030
var immutablePercentage: Double = 0.0
3131

32+
/**
33+
* Adds [size] elements to an empty persistent list builder.
34+
*
35+
* Expected time: nearly constant.
36+
* Expected memory: nearly constant.
37+
*/
3238
@Benchmark
3339
fun addLast(): PersistentList.Builder<String> {
3440
return persistentListBuilderAdd(size, immutablePercentage)
3541
}
3642

43+
/**
44+
* Adds [size] elements to an empty persistent list builder and then iterates all elements from first to last.
45+
*
46+
* Expected time: [addLast] + [Iterate.firstToLast]
47+
* Expected memory: [addLast] + [Iterate.firstToLast]
48+
*/
3749
@Benchmark
3850
fun addLastAndIterate(bh: Blackhole) {
3951
val builder = persistentListBuilderAdd(size, immutablePercentage)
@@ -42,6 +54,12 @@ open class Add {
4254
}
4355
}
4456

57+
/**
58+
* Adds [size] elements to an empty persistent list builder and then gets all elements by index from first to last.
59+
*
60+
* Expected time: [addLast] + [Get.getByIndex]
61+
* Expected memory: [addLast] + [Get.getByIndex]
62+
*/
4563
@Benchmark
4664
fun addLastAndGet(bh: Blackhole) {
4765
val builder = persistentListBuilderAdd(size, immutablePercentage)

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/builder/Get.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ open class Get {
3636
builder = persistentListBuilderAdd(size, immutablePercentage)
3737
}
3838

39+
/**
40+
* Gets every element by index starting from first to last.
41+
*
42+
* Expected time: logarithmic
43+
* Expected memory: none
44+
*/
3945
@Benchmark
4046
fun getByIndex(bh: Blackhole) {
4147
for (i in 0 until builder.size) {

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/builder/Iterate.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,25 @@ open class Iterate {
3636
builder = persistentListBuilderAdd(size, immutablePercentage)
3737
}
3838

39+
/**
40+
* Iterates every element starting from first to last.
41+
*
42+
* Expected time: nearly constant
43+
* Expected memory: none once iterator created
44+
*/
3945
@Benchmark
4046
fun firstToLast(bh: Blackhole) {
4147
for (e in builder) {
4248
bh.consume(e)
4349
}
4450
}
4551

52+
/**
53+
* Iterates every element starting from last to first.
54+
*
55+
* Expected time: nearly constant
56+
* Expected memory: none once iterator created
57+
*/
4658
@Benchmark
4759
fun lastToFirst(bh: Blackhole) {
4860
val iterator = builder.listIterator(size)

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/builder/Remove.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ open class Remove {
2828
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
2929
var immutablePercentage: Double = 0.0
3030

31+
/**
32+
* Adds [size] elements to an empty persistent list builder and then removes each element by index starting from last to first.
33+
*
34+
* Expected time: [Add.addLast] + nearly constant.
35+
* Expected memory: [Add.addLast] + nearly constant.
36+
*/
3137
@Benchmark
3238
fun addAndRemoveLast(): PersistentList.Builder<String> {
3339
val builder = persistentListBuilderAdd(size, immutablePercentage)

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/builder/Set.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ open class Set {
3838
randomIndices = List(size) { it }.shuffled()
3939
}
4040

41+
/**
42+
* Updates each element by index starting from first to last.
43+
*
44+
* Expected time: logarithmic
45+
* Expected memory: nearly constant
46+
*/
4147
@Benchmark
4248
fun setByIndex(): PersistentList.Builder<String> {
4349
for (i in 0 until size) {
@@ -46,6 +52,12 @@ open class Set {
4652
return builder
4753
}
4854

55+
/**
56+
* Updates each element by index randomly.
57+
*
58+
* Expected time: logarithmic
59+
* Expected memory: nearly constant
60+
*/
4961
@Benchmark
5062
fun setByRandomIndex(): PersistentList.Builder<String> {
5163
for (i in 0 until size) {

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableMap/Get.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ open class Get {
4444
keys = generateKeys(hashCodeType, size)
4545
}
4646

47+
/**
48+
* Gets every value by key.
49+
*
50+
* Expected time: logarithmic
51+
* Expected memory: none
52+
*/
4753
@Benchmark
4854
fun get(bh: Blackhole) {
4955
repeat(times = size) { index ->

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableMap/Iterate.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,38 @@ open class Iterate {
3939
persistentMap = persistentMapPut(implementation, generateKeys(hashCodeType, size))
4040
}
4141

42+
/**
43+
* Iterates all keys.
44+
*
45+
* Expected time: nearly constant (logarithmic for ordered persistent map)
46+
* Expected memory: none once iterator is created.
47+
*/
4248
@Benchmark
4349
fun iterateKeys(bh: Blackhole) {
4450
for (k in persistentMap.keys) {
4551
bh.consume(k)
4652
}
4753
}
4854

55+
/**
56+
* Iterates all values.
57+
*
58+
* Expected time: nearly constant (logarithmic for ordered persistent map)
59+
* Expected memory: none once iterator is created.
60+
*/
4961
@Benchmark
5062
fun iterateValues(bh: Blackhole) {
5163
for (v in persistentMap.values) {
5264
bh.consume(v)
5365
}
5466
}
5567

68+
/**
69+
* Iterates all entries.
70+
*
71+
* Expected time: nearly constant (logarithmic for ordered persistent map)
72+
* Expected memory: constant.
73+
*/
5674
@Benchmark
5775
fun iterateEntries(bh: Blackhole) {
5876
for (e in persistentMap) {

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableMap/Put.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,23 @@ open class Put {
3939
keys = generateKeys(hashCodeType, size)
4040
}
4141

42+
/**
43+
* Adds [size] entries to an empty persistent map.
44+
*
45+
* Expected time: logarithmic
46+
* Expected memory: logarithmic
47+
*/
4248
@Benchmark
4349
fun put(): PersistentMap<IntWrapper, String> {
4450
return persistentMapPut(implementation, keys)
4551
}
4652

53+
/**
54+
* Adds [size] entries to an empty persistent map and then gets every value by key.
55+
*
56+
* Expected time: [put] + [Get.get]
57+
* Expected memory: [put] + [Get.get]
58+
*/
4759
@Benchmark
4860
fun putAndGet(bh: Blackhole) {
4961
val map = persistentMapPut(implementation, keys)
@@ -52,6 +64,12 @@ open class Put {
5264
}
5365
}
5466

67+
/**
68+
* Adds [size] entries to an empty persistent map and then iterates all keys.
69+
*
70+
* Expected time: [put] + [Iterate.iterateKeys]
71+
* Expected memory: [put] + [Iterate.iterateKeys]
72+
*/
5573
@Benchmark
5674
fun putAndIterateKeys(bh: Blackhole) {
5775
val map = persistentMapPut(implementation, keys)

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableMap/Remove.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ open class Remove {
4444
keys = generateKeys(hashCodeType, size)
4545
}
4646

47+
/**
48+
* Removes each entry by key.
49+
*
50+
* Expected time: logarithmic
51+
* Expected memory: logarithmic
52+
*/
4753
@Benchmark
4854
fun remove(): PersistentMap<IntWrapper, String> {
4955
var map = persistentMap

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableMap/builder/Get.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ open class Get {
4747
keys = generateKeys(hashCodeType, size)
4848
}
4949

50+
/**
51+
* Gets every value by key.
52+
*
53+
* Expected time: logarithmic
54+
* Expected memory: none
55+
*/
5056
@Benchmark
5157
fun get(bh: Blackhole) {
5258
repeat(times = size) { index ->

benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableMap/builder/Iterate.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,38 @@ open class Iterate {
4343
builder = persistentMapBuilderPut(implementation, keys, immutablePercentage)
4444
}
4545

46+
/**
47+
* Iterates all keys.
48+
*
49+
* Expected time: nearly constant (logarithmic for ordered persistent map)
50+
* Expected memory: none once iterator is created.
51+
*/
4652
@Benchmark
4753
fun iterateKeys(bh: Blackhole) {
4854
for (k in builder.keys) {
4955
bh.consume(k)
5056
}
5157
}
5258

59+
/**
60+
* Iterates all values.
61+
*
62+
* Expected time: nearly constant (logarithmic for ordered persistent map)
63+
* Expected memory: constant.
64+
*/
5365
@Benchmark
5466
fun iterateValues(bh: Blackhole) {
5567
for (v in builder.values) {
5668
bh.consume(v)
5769
}
5870
}
5971

72+
/**
73+
* Iterates all entries.
74+
*
75+
* Expected time: nearly constant (logarithmic for ordered persistent map)
76+
* Expected memory: constant.
77+
*/
6078
@Benchmark
6179
fun iterateEntries(bh: Blackhole) {
6280
for (e in builder) {

0 commit comments

Comments
 (0)