Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment benchmark methods #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Add.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,27 @@ open class Add {
@Param(BM_1, BM_10, BM_100, BM_1000, BM_10000, BM_100000, BM_1000000, BM_10000000)
var size: Int = 0

/**
* Adds [size] elements to an empty persistent list.
*
* Measures mean time and memory spent per `add` operation.
*
* Expected time: nearly constant.
* Expected memory: for size in 1..32 - O(size), nearly constant otherwise.
*/
@Benchmark
fun addLast(): ImmutableList<String> {
return persistentListAdd(size)
}

/**
* Adds [size] elements to an empty persistent list and then iterates all elements from first to last.
*
* Measures mean time and memory spent per `add` and `next` operations.
*
* Expected time: [addLast] + [Iterate.firstToLast]
* Expected memory: [addLast] + [Iterate.firstToLast]
*/
@Benchmark
fun addLastAndIterate(bh: Blackhole) {
val list = persistentListAdd(size)
Expand All @@ -39,6 +55,14 @@ open class Add {
}
}

/**
* Adds [size] elements to an empty persistent list and then gets all elements by index from first to last.
*
* Measures mean time and memory spent per `add` and `get` operations.
*
* Expected time: [addLast] + [Get.getByIndex]
* Expected memory: [addLast] + [Get.getByIndex]
*/
@Benchmark
fun addLastAndGet(bh: Blackhole) {
val list = persistentListAdd(size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ open class Get {
persistentList = persistentListAdd(size)
}

/**
* Gets every element by index starting from first to last.
*
* Measures mean time and memory spent per `get` operation.
*
* Expected time: logarithmic
* Expected memory: none
*/
@Benchmark
fun getByIndex(bh: Blackhole) {
for (i in 0 until persistentList.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,29 @@ open class Iterate {
persistentList = persistentListAdd(size)
}

/**
* Iterates every element starting from first to last.
*
* Measures mean time and memory spent per `next` operation.
*
* Expected time: nearly constant
* Expected memory: none once iterator created
*/
@Benchmark
fun firstToLast(bh: Blackhole) {
for (e in persistentList) {
bh.consume(e)
}
}

/**
* Iterates every element starting from last to first.
*
* Measures mean time and memory spent per `previous` operation.
*
* Expected time: nearly constant
* Expected memory: none once iterator created
*/
@Benchmark
fun lastToFirst(bh: Blackhole) {
val iterator = persistentList.listIterator(size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ open class Remove {
persistentList = persistentListAdd(size)
}

/**
* Removes all elements by index starting from last to first.
*
* Measures mean time and memory spent per `removeAt` operation.
*
* Expected time: nearly constant.
* Expected memory: for size in 1..32 - O(size), nearly constant otherwise.
*/
@Benchmark
fun removeLast(): ImmutableList<String> {
var list = persistentList
Expand Down
16 changes: 16 additions & 0 deletions benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableList/Set.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ open class Set {
randomIndices = List(size) { it }.shuffled()
}

/**
* Updates each element by index starting from first to last.
*
* Measures mean time and memory spent per `set` operation.
*
* Expected time: logarithmic
* Expected memory: logarithmic
*/
@Benchmark
fun setByIndex(): ImmutableList<String> {
repeat(times = size) { index ->
Expand All @@ -44,6 +52,14 @@ open class Set {
return persistentList
}

/**
* Updates each element by index randomly.
*
* Measures mean time and memory spent per `set` operation.
*
* Expected time: logarithmic
* Expected memory: logarithmic
*/
@Benchmark
fun setByRandomIndex(): ImmutableList<String> {
repeat(times = size) { index ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,27 @@ open class Add {
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
var immutablePercentage: Double = 0.0

/**
* Adds [size] elements to an empty persistent list builder.
*
* Measures mean time and memory spent per `add` operation.
*
* Expected time: nearly constant.
* Expected memory: nearly constant.
*/
@Benchmark
fun addLast(): PersistentList.Builder<String> {
return persistentListBuilderAdd(size, immutablePercentage)
}

/**
* Adds [size] elements to an empty persistent list builder and then iterates all elements from first to last.
*
* Measures mean time and memory spent per `add` and `next` operations.
*
* Expected time: [addLast] + [Iterate.firstToLast]
* Expected memory: [addLast] + [Iterate.firstToLast]
*/
@Benchmark
fun addLastAndIterate(bh: Blackhole) {
val builder = persistentListBuilderAdd(size, immutablePercentage)
Expand All @@ -42,6 +58,14 @@ open class Add {
}
}

/**
* Adds [size] elements to an empty persistent list builder and then gets all elements by index from first to last.
*
* Measures mean time and memory spent per `add` and `get` operations.
*
* Expected time: [addLast] + [Get.getByIndex]
* Expected memory: [addLast] + [Get.getByIndex]
*/
@Benchmark
fun addLastAndGet(bh: Blackhole) {
val builder = persistentListBuilderAdd(size, immutablePercentage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ open class Get {
builder = persistentListBuilderAdd(size, immutablePercentage)
}

/**
* Gets every element by index starting from first to last.
*
* Measures mean time and memory spent per `get` operation.
*
* Expected time: logarithmic
* Expected memory: none
*/
@Benchmark
fun getByIndex(bh: Blackhole) {
for (i in 0 until builder.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,29 @@ open class Iterate {
builder = persistentListBuilderAdd(size, immutablePercentage)
}

/**
* Iterates every element starting from first to last.
*
* Measures mean time and memory spent per `next` operation.
*
* Expected time: nearly constant
* Expected memory: none once iterator created
*/
@Benchmark
fun firstToLast(bh: Blackhole) {
for (e in builder) {
bh.consume(e)
}
}

/**
* Iterates every element starting from last to first.
*
* Measures mean time and memory spent per `previous` operation.
*
* Expected time: nearly constant
* Expected memory: none once iterator created
*/
@Benchmark
fun lastToFirst(bh: Blackhole) {
val iterator = builder.listIterator(size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ open class Remove {
@Param(IP_100, IP_99_09, IP_95, IP_70, IP_50, IP_30, IP_0)
var immutablePercentage: Double = 0.0

/**
* Adds [size] elements to an empty persistent list builder and then removes each element by index starting from last to first.
*
* Measures mean time and memory spent per `add` and `removeAt` operations.
*
* Expected time: [Add.addLast] + nearly constant.
* Expected memory: [Add.addLast] + nearly constant.
*/
@Benchmark
fun addAndRemoveLast(): PersistentList.Builder<String> {
val builder = persistentListBuilderAdd(size, immutablePercentage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ open class Set {
randomIndices = List(size) { it }.shuffled()
}

/**
* Updates each element by index starting from first to last.
*
* Measures mean time and memory spent per `set` operation.
*
* Expected time: logarithmic
* Expected memory: nearly constant
*/
@Benchmark
fun setByIndex(): PersistentList.Builder<String> {
for (i in 0 until size) {
Expand All @@ -46,6 +54,14 @@ open class Set {
return builder
}

/**
* Updates each element by index randomly.
*
* Measures mean time and memory spent per `set` operation.
*
* Expected time: logarithmic
* Expected memory: nearly constant
*/
@Benchmark
fun setByRandomIndex(): PersistentList.Builder<String> {
for (i in 0 until size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ open class Get {
keys = generateKeys(hashCodeType, size)
}

/**
* Gets every value by key.
*
* Measures mean time and memory spent per `get` operation.
*
* Expected time: logarithmic
* Expected memory: none
*/
@Benchmark
fun get(bh: Blackhole) {
repeat(times = size) { index ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,44 @@ open class Iterate {
persistentMap = persistentMapPut(implementation, generateKeys(hashCodeType, size))
}

/**
* Iterates all keys.
*
* Measures mean time and memory spent per `next` operation.
*
* Expected time: nearly constant (logarithmic for ordered persistent map)
* Expected memory: none once iterator is created.
*/
@Benchmark
fun iterateKeys(bh: Blackhole) {
for (k in persistentMap.keys) {
bh.consume(k)
}
}

/**
* Iterates all values.
*
* Measures mean time and memory spent per `next` operation.
*
* Expected time: nearly constant (logarithmic for ordered persistent map)
* Expected memory: none once iterator is created.
*/
@Benchmark
fun iterateValues(bh: Blackhole) {
for (v in persistentMap.values) {
bh.consume(v)
}
}

/**
* Iterates all entries.
*
* Measures mean time and memory spent per `next` operation.
*
* Expected time: nearly constant (logarithmic for ordered persistent map)
* Expected memory: constant.
*/
@Benchmark
fun iterateEntries(bh: Blackhole) {
for (e in persistentMap) {
Expand Down
24 changes: 24 additions & 0 deletions benchmarks-mpp/src/jvmMain/kotlin/benchmarks/immutableMap/Put.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,27 @@ open class Put {
keys = generateKeys(hashCodeType, size)
}

/**
* Adds [size] entries to an empty persistent map.
*
* Measures mean time and memory spent per `put` operation.
*
* Expected time: logarithmic
* Expected memory: logarithmic
*/
@Benchmark
fun put(): PersistentMap<IntWrapper, String> {
return persistentMapPut(implementation, keys)
}

/**
* Adds [size] entries to an empty persistent map and then gets every value by key.
*
* Measures mean time and memory spent per `put` and `get` operations.
*
* Expected time: [put] + [Get.get]
* Expected memory: [put] + [Get.get]
*/
@Benchmark
fun putAndGet(bh: Blackhole) {
val map = persistentMapPut(implementation, keys)
Expand All @@ -52,6 +68,14 @@ open class Put {
}
}

/**
* Adds [size] entries to an empty persistent map and then iterates all keys.
*
* Measures mean time and memory spent per `put` and `next` operations.
*
* Expected time: [put] + [Iterate.iterateKeys]
* Expected memory: [put] + [Iterate.iterateKeys]
*/
@Benchmark
fun putAndIterateKeys(bh: Blackhole) {
val map = persistentMapPut(implementation, keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ open class Remove {
keys = generateKeys(hashCodeType, size)
}

/**
* Removes each entry by key.
*
* Measures mean time and memory spent per `remove` operation.
*
* Expected time: logarithmic
* Expected memory: logarithmic
*/
@Benchmark
fun remove(): PersistentMap<IntWrapper, String> {
var map = persistentMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ open class Get {
keys = generateKeys(hashCodeType, size)
}

/**
* Gets every value by key.
*
* Measures mean time and memory spent per `get` operation.
*
* Expected time: logarithmic
* Expected memory: none
*/
@Benchmark
fun get(bh: Blackhole) {
repeat(times = size) { index ->
Expand Down
Loading