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) {

0 commit comments

Comments
 (0)