Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.