diff --git a/src/benchmark/kotlin/com/github/michaelbull/result/AndThenBenchmark.kt b/src/benchmark/kotlin/com/github/michaelbull/result/AndThenBenchmark.kt deleted file mode 100644 index a5be611..0000000 --- a/src/benchmark/kotlin/com/github/michaelbull/result/AndThenBenchmark.kt +++ /dev/null @@ -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 = Ok(1) - private fun provideY(): Result = Ok(2) - private fun provideZ(): Result = Err(Error) - } -} diff --git a/src/benchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt b/src/benchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt index 36da1c6..5b06005 100644 --- a/src/benchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt +++ b/src/benchmark/kotlin/com/github/michaelbull/result/BindingBenchmark.kt @@ -16,7 +16,7 @@ class BindingBenchmark { private object Error @Benchmark - fun success(blackhole: Blackhole) { + fun bindingSuccess(blackhole: Blackhole) { val result = binding { val x = provideX().bind() val y = provideY().bind() @@ -27,7 +27,7 @@ class BindingBenchmark { } @Benchmark - fun failure(blackhole: Blackhole) { + fun bindingFailure(blackhole: Blackhole) { val result = binding { val x = provideX().bind() val z = provideZ().bind() @@ -37,6 +37,30 @@ class BindingBenchmark { 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) private companion object { private fun provideX(): Result = Ok(1)