[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() }),
|
"Richards" to BenchmarkEntryWithInit.create(::RichardsBenchmark, { runRichards() }),
|
||||||
"Singleton.access" to BenchmarkEntryWithInit.create(::SingletonBenchmark, { access() }),
|
"Singleton.access" to BenchmarkEntryWithInit.create(::SingletonBenchmark, { access() }),
|
||||||
"Splay" to BenchmarkEntryWithInitAndValidation.create(::SplayBenchmark, { runSplay() }, { splayTearDown() }),
|
"Splay" to BenchmarkEntryWithInitAndValidation.create(::SplayBenchmark, { runSplay() }, { splayTearDown() }),
|
||||||
|
"SplayWithWorkers" to BenchmarkEntryWithInitAndValidation.create(::SplayBenchmarkUsingWorkers, { runSplayWorkers() }, { splayTearDownWorkers() }),
|
||||||
"String.stringConcat" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringConcat() }),
|
"String.stringConcat" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringConcat() }),
|
||||||
"String.stringBuilderConcat" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringBuilderConcat() }),
|
"String.stringBuilderConcat" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringBuilderConcat() }),
|
||||||
"String.stringBuilderConcatNullable" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringBuilderConcatNullable() }),
|
"String.stringBuilderConcatNullable" to BenchmarkEntryWithInit.create(::StringBenchmark, { stringBuilderConcatNullable() }),
|
||||||
@@ -229,6 +230,13 @@ class RingLauncher : Launcher() {
|
|||||||
"LocalObjects.localArray" to BenchmarkEntryWithInit.create(::LocalObjectsBenchmark, { localArray() }),
|
"LocalObjects.localArray" to BenchmarkEntryWithInit.create(::LocalObjectsBenchmark, { localArray() }),
|
||||||
"ComplexArrays.outerProduct" to BenchmarkEntryWithInit.create(::ComplexArraysBenchmark, { outerProduct() }),
|
"ComplexArrays.outerProduct" to BenchmarkEntryWithInit.create(::ComplexArraysBenchmark, { outerProduct() }),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
init {
|
||||||
|
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||||
|
if (!isExperimentalMM()) {
|
||||||
|
baseBenchmarksSet -= listOf("SplayWithWorkers")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
// also has to deal with a lot of changes to the large tree object
|
// also has to deal with a lot of changes to the large tree object
|
||||||
// graph.
|
// graph.
|
||||||
|
|
||||||
|
import kotlin.native.concurrent.*
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
// A splay tree is a self-balancing binary search tree with the additional
|
// 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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+3
-3
@@ -50,9 +50,6 @@ abstract class Launcher {
|
|||||||
while (i-- > 0) benchmark.lambda(benchmarkInstance!!)
|
while (i-- > 0) benchmark.lambda(benchmarkInstance!!)
|
||||||
cleanup()
|
cleanup()
|
||||||
}
|
}
|
||||||
if (benchmark is BenchmarkEntryWithInitAndValidation) {
|
|
||||||
benchmark.validation(benchmarkInstance!!)
|
|
||||||
}
|
|
||||||
result
|
result
|
||||||
} else if (benchmark is BenchmarkEntry) {
|
} else if (benchmark is BenchmarkEntry) {
|
||||||
cleanup()
|
cleanup()
|
||||||
@@ -109,6 +106,9 @@ abstract class Launcher {
|
|||||||
// Save benchmark object
|
// Save benchmark object
|
||||||
recordMeasurement(RecordTimeMeasurement(BenchmarkResult.Status.PASSED, k, numWarmIterations, scaledTime))
|
recordMeasurement(RecordTimeMeasurement(BenchmarkResult.Status.PASSED, k, numWarmIterations, scaledTime))
|
||||||
}
|
}
|
||||||
|
if (benchmark is BenchmarkEntryWithInitAndValidation) {
|
||||||
|
benchmark.validation(benchmarkInstance!!)
|
||||||
|
}
|
||||||
logger.log("\n", usePrefix = false)
|
logger.log("\n", usePrefix = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user