Created
January 15, 2020 09:08
-
-
Save akarnokd/fef7a5cfe3fad98f8b8a8a1cc8dfffcc to your computer and use it in GitHub Desktop.
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
package hu.akarnokd.kotlin | |
import io.reactivex.rxjava3.core.Completable | |
import io.reactivex.rxjava3.schedulers.Schedulers | |
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.launch | |
object RepeatBench { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
repeat(100) { | |
bench2(); | |
Thread.sleep(100) | |
} | |
} | |
fun bench1() { | |
val timeCoroutineStart = System.currentTimeMillis() | |
CoroutineScope(Dispatchers.IO).launch { | |
var i = 0 | |
repeat(1000000000) { | |
i++ | |
} | |
println("COROUTINE: ${System.currentTimeMillis() - timeCoroutineStart}") | |
} | |
} | |
fun bench2() { | |
val timeRxStart = System.currentTimeMillis() | |
Completable.create{ | |
var i = 0 | |
repeat(1000000000) { | |
i++ | |
} | |
it.onComplete() | |
}.subscribeOn(Schedulers.io()).subscribe { | |
println("RX: ${System.currentTimeMillis() - timeRxStart}") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment