Created
April 14, 2020 09:31
-
-
Save SergejIsbrecht/2b0bf1b99d9f942c8717cbf619d39ab6 to your computer and use it in GitHub Desktop.
bench.jmh.seq
This file contains hidden or 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 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