Skip to content

Instantly share code, notes, and snippets.

@akarnokd
Created January 15, 2020 09:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akarnokd/fef7a5cfe3fad98f8b8a8a1cc8dfffcc to your computer and use it in GitHub Desktop.
Save akarnokd/fef7a5cfe3fad98f8b8a8a1cc8dfffcc to your computer and use it in GitHub Desktop.
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