Merge {AndThen,Binding}Benchmarks
jmh-visualiser displays them comparatively when they are in the same class.
This commit is contained in:
parent
0910e9ffe4
commit
4b745d8717
@ -1,48 +0,0 @@
|
|||||||
package com.github.michaelbull.result
|
|
||||||
|
|
||||||
import org.openjdk.jmh.annotations.Benchmark
|
|
||||||
import org.openjdk.jmh.annotations.BenchmarkMode
|
|
||||||
import org.openjdk.jmh.annotations.Mode
|
|
||||||
import org.openjdk.jmh.annotations.OutputTimeUnit
|
|
||||||
import org.openjdk.jmh.annotations.Scope
|
|
||||||
import org.openjdk.jmh.annotations.State
|
|
||||||
import org.openjdk.jmh.infra.Blackhole
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
@BenchmarkMode(Mode.Throughput)
|
|
||||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
|
||||||
class AndThenBenchmark {
|
|
||||||
|
|
||||||
private object Error
|
|
||||||
|
|
||||||
@Benchmark
|
|
||||||
fun success(blackhole: Blackhole) {
|
|
||||||
val result =
|
|
||||||
provideX().andThen { first ->
|
|
||||||
provideY().andThen { second ->
|
|
||||||
Ok(first + second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
blackhole.consume(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Benchmark
|
|
||||||
fun failure(blackhole: Blackhole) {
|
|
||||||
val result =
|
|
||||||
provideX().andThen { first ->
|
|
||||||
provideZ().andThen { second ->
|
|
||||||
Ok(first + second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
blackhole.consume(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@State(Scope.Thread)
|
|
||||||
private companion object {
|
|
||||||
private fun provideX(): Result<Int, Error> = Ok(1)
|
|
||||||
private fun provideY(): Result<Int, Error> = Ok(2)
|
|
||||||
private fun provideZ(): Result<Int, Error> = Err(Error)
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,7 +16,7 @@ class BindingBenchmark {
|
|||||||
private object Error
|
private object Error
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
fun success(blackhole: Blackhole) {
|
fun bindingSuccess(blackhole: Blackhole) {
|
||||||
val result = binding<Int, Error> {
|
val result = binding<Int, Error> {
|
||||||
val x = provideX().bind()
|
val x = provideX().bind()
|
||||||
val y = provideY().bind()
|
val y = provideY().bind()
|
||||||
@ -27,7 +27,7 @@ class BindingBenchmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
fun failure(blackhole: Blackhole) {
|
fun bindingFailure(blackhole: Blackhole) {
|
||||||
val result = binding<Int, Error> {
|
val result = binding<Int, Error> {
|
||||||
val x = provideX().bind()
|
val x = provideX().bind()
|
||||||
val z = provideZ().bind()
|
val z = provideZ().bind()
|
||||||
@ -37,6 +37,30 @@ class BindingBenchmark {
|
|||||||
blackhole.consume(result)
|
blackhole.consume(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun andThenSuccess(blackhole: Blackhole) {
|
||||||
|
val result =
|
||||||
|
provideX().andThen { first ->
|
||||||
|
provideY().andThen { second ->
|
||||||
|
Ok(first + second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
blackhole.consume(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
fun andThenFailure(blackhole: Blackhole) {
|
||||||
|
val result =
|
||||||
|
provideX().andThen { first ->
|
||||||
|
provideZ().andThen { second ->
|
||||||
|
Ok(first + second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
blackhole.consume(result)
|
||||||
|
}
|
||||||
|
|
||||||
@State(Scope.Thread)
|
@State(Scope.Thread)
|
||||||
private companion object {
|
private companion object {
|
||||||
private fun provideX(): Result<Int, Error> = Ok(1)
|
private fun provideX(): Result<Int, Error> = Ok(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user