Skip to content

Instantly share code, notes, and snippets.

@SergejIsbrecht
Created April 14, 2020 09:31
Show Gist options
  • Save SergejIsbrecht/2b0bf1b99d9f942c8717cbf619d39ab6 to your computer and use it in GitHub Desktop.
Save SergejIsbrecht/2b0bf1b99d9f942c8717cbf619d39ab6 to your computer and use it in GitHub Desktop.
bench.jmh.seq
package io
import io.reactivex.Flowable
import io.vavr.collection.Iterator
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole
import java.util.concurrent.TimeUnit
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
@Fork(value = 2)
@Warmup(iterations = 2)
@Measurement(iterations = 3)
open class Iterate {
var fromZero = 0
var fromOne = 1
var to = 1_000_000
@Benchmark
fun kotlin_range_seq_last(blackhole: Blackhole) {
blackhole.consume((fromOne..to)
.asSequence()
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.last())
}
@Benchmark
fun kotlin_range_default_last(blackhole: Blackhole) {
blackhole.consume((fromOne..to)
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.last())
}
@Benchmark
fun kotlin_range_rxjava_last(blackhole: Blackhole) {
blackhole.consume(Flowable.range(fromZero, to)
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.blockingLast())
}
@Benchmark
fun kotlin_range_seq_first(blackhole: Blackhole) {
blackhole.consume((fromOne..to)
.asSequence()
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.first())
}
@Benchmark
fun kotlin_range_default_first(blackhole: Blackhole) {
blackhole.consume((fromOne..to)
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.first())
}
@Benchmark
fun kotlin_range_rxjava_first(blackhole: Blackhole) {
blackhole.consume(Flowable.range(fromZero, to)
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.blockingFirst())
}
@Benchmark
fun kotlin_range_vavr_iterator_first(blackhole: Blackhole) {
blackhole.consume(Iterator.range(fromZero, to)
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.map { it + 1 }
.get())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment