[K/N] Add concurrent version of Splay benchmark
This commit is contained in:
@@ -61,6 +61,7 @@ class RingLauncher : Launcher() {
|
||||
"Richards" to BenchmarkEntryWithInit.create(::RichardsBenchmark, { runRichards() }),
|
||||
"Singleton.access" to BenchmarkEntryWithInit.create(::SingletonBenchmark, { access() }),
|
||||
"Splay" to BenchmarkEntryWithInitAndValidation.create(::SplayBenchmark, { runSplay() }, { splayTearDown() }),
|
||||
"SplayWithWorkers" to BenchmarkEntryWithInitAndValidation.create(::SplayBenchmarkUsingWorkers, { runSplayWorkers() }, { splayTearDownWorkers() }),
|
||||
"String.stringConcat" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringConcat() }),
|
||||
"String.stringBuilderConcat" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringBuilderConcat() }),
|
||||
"String.stringBuilderConcatNullable" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringBuilderConcatNullable() }),
|
||||
@@ -229,6 +230,13 @@ class RingLauncher : Launcher() {
|
||||
"LocalObjects.localArray" to BenchmarkEntryWithInit.create(::LocalObjectsBenchmark, { localArray() }),
|
||||
"ComplexArrays.outerProduct" to BenchmarkEntryWithInit.create(::ComplexArraysBenchmark, { outerProduct() }),
|
||||
)
|
||||
|
||||
init {
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
if (!isExperimentalMM()) {
|
||||
baseBenchmarksSet -= listOf("SplayWithWorkers")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
// also has to deal with a lot of changes to the large tree object
|
||||
// graph.
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.random.Random
|
||||
|
||||
// A splay tree is a self-balancing binary search tree with the additional
|
||||
@@ -301,3 +302,20 @@ class SplayBenchmark {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SplayBenchmarkUsingWorkers {
|
||||
val numberOfWorkers = 5;
|
||||
val workers = Array(numberOfWorkers, { _ -> Worker.start() })
|
||||
val splayTrees = Array(numberOfWorkers, { _ -> SplayBenchmark() });
|
||||
|
||||
fun runSplayWorkers() {
|
||||
val futures = Array(numberOfWorkers) {i -> workers[i].execute(TransferMode.SAFE, { splayTrees[i] }, {it.runSplay()})};
|
||||
futures.forEach{it.consume {}};
|
||||
}
|
||||
|
||||
fun splayTearDownWorkers() {
|
||||
val futures = Array(numberOfWorkers) {i -> workers[i].execute(TransferMode.SAFE, { splayTrees[i] }, {it.splayTearDown()})};
|
||||
futures.forEach{it.consume {}};
|
||||
workers.forEach { it.requestTermination().result }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user