Skip to content

Commit

Permalink
Make CoroutineScope the receiver in awaitAsync10KTransactions and…
Browse files Browse the repository at this point in the history
… extract `awaitAsync10K`
  • Loading branch information
ShreckYe committed Nov 19, 2024
1 parent 3715550 commit 920627f
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() {
repeat(`10K`) { transaction(database) {} }
}

private suspend fun awaitAsync10KTransactions() =
coroutineScope {
List(`10K`) { async { transaction(database) {} } }.awaitAll()
}
@Suppress("SuspendFunctionOnCoroutineScope")
private suspend inline fun CoroutineScope.awaitAsync10K(crossinline block: () -> Unit) =
List(`10K`) { async { block() } }.awaitAll()

@Suppress("SuspendFunctionOnCoroutineScope")
private suspend fun CoroutineScope.awaitAsync10KTransactions() =
awaitAsync10K { transaction(database) {} }

@Benchmark
fun singleThreadConcurrent10KTransactions() =
Expand Down Expand Up @@ -93,14 +96,14 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() {
@Benchmark
fun multiThreadConcurrent10KTransactionsWithThreadLocalDatabases() {
runBlocking(dispatcherWithThreadLocalDatabases) {
List(`10K`) { async { transaction(databaseThreadLocal.get()) {} } }.awaitAll()
awaitAsync10K { transaction(databaseThreadLocal.get()) {} }
}
}

@Benchmark
fun multiThreadConcurrent10KTransactionsWithImplicitThreadLocalDatabases() {
runBlocking(dispatcherWithThreadLocalDatabases) {
List(`10K`) { async { transaction {} } }.awaitAll()
awaitAsync10K { transaction {} }
}
}
}

0 comments on commit 920627f

Please sign in to comment.