forked from Kotlin/kotlinx.coroutines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Kotlin#1652 from Kotlin/scheduler-changes
CoroutineScheduler rework Fixes Kotlin#840 Fixes Kotlin#1046 Fixes Kotlin#1286
- Loading branch information
Showing
31 changed files
with
1,003 additions
and
1,042 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
benchmarks/src/jmh/kotlin/benchmarks/ChannelProducerConsumerBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
benchmarks/src/jmh/kotlin/benchmarks/scheduler/DispatchersContextSwitchBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package benchmarks.scheduler | ||
|
||
import benchmarks.akka.* | ||
import kotlinx.coroutines.* | ||
import org.openjdk.jmh.annotations.* | ||
import org.openjdk.jmh.annotations.State | ||
import java.lang.Thread.* | ||
import java.util.concurrent.* | ||
import kotlin.concurrent.* | ||
import kotlin.coroutines.* | ||
|
||
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@Fork(value = 1) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Thread) | ||
open class DispatchersContextSwitchBenchmark { | ||
private val nCoroutines = 10000 | ||
private val delayTimeMs = 1L | ||
private val nRepeatDelay = 10 | ||
|
||
private val fjp = ForkJoinPool.commonPool().asCoroutineDispatcher() | ||
private val ftp = Executors.newFixedThreadPool(CORES_COUNT - 1).asCoroutineDispatcher() | ||
|
||
@TearDown | ||
fun teardown() { | ||
ftp.close() | ||
(ftp.executor as ExecutorService).awaitTermination(1, TimeUnit.SECONDS) | ||
} | ||
|
||
@Benchmark | ||
fun coroutinesIoDispatcher() = runBenchmark(Dispatchers.IO) | ||
|
||
@Benchmark | ||
fun coroutinesDefaultDispatcher() = runBenchmark(Dispatchers.Default) | ||
|
||
@Benchmark | ||
fun coroutinesFjpDispatcher() = runBenchmark(fjp) | ||
|
||
@Benchmark | ||
fun coroutinesFtpDispatcher() = runBenchmark(ftp) | ||
|
||
@Benchmark | ||
fun coroutinesBlockingDispatcher() = runBenchmark(EmptyCoroutineContext) | ||
|
||
@Benchmark | ||
fun threads() { | ||
val threads = List(nCoroutines) { | ||
thread(start = true) { | ||
repeat(nRepeatDelay) { | ||
sleep(delayTimeMs) | ||
} | ||
} | ||
} | ||
threads.forEach { it.join() } | ||
} | ||
|
||
private fun runBenchmark(dispatcher: CoroutineContext) = runBlocking { | ||
repeat(nCoroutines) { | ||
launch(dispatcher) { | ||
repeat(nRepeatDelay) { | ||
delay(delayTimeMs) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.