Skip to content

Commit 2812770

Browse files
committed
Move arrow benchmarks to jvmMain sourceSet
CI is failing on finding android builds for arrow-core.
1 parent 56b066a commit 2812770

File tree

4 files changed

+54
-75
lines changed

4 files changed

+54
-75
lines changed

benchmarks/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ kotlin {
2323
implementation(project(":kotlin-result-coroutines"))
2424
implementation(libs.kotlin.benchmark.runtime)
2525
implementation(libs.kotlin.coroutines.core)
26+
}
27+
}
28+
29+
jvmMain {
30+
dependencies {
2631
implementation(libs.arrow)
2732
}
2833
}
Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package com.github.michaelbull.result
22

3-
import arrow.core.raise.either
4-
import arrow.core.Either
5-
import arrow.core.flatMap
6-
import arrow.core.left
7-
import arrow.core.right
83
import kotlinx.benchmark.Benchmark
94
import kotlinx.benchmark.BenchmarkMode
105
import kotlinx.benchmark.BenchmarkTimeUnit
@@ -41,79 +36,9 @@ class BindingBenchmark {
4136
blackhole.consume(result)
4237
}
4338

44-
@Benchmark
45-
fun arrowBindingSuccess(blackhole: Blackhole) {
46-
val result: Either<Error, Int> = either {
47-
val x = arrowProvideX().bind()
48-
val y = arrowProvideY().bind()
49-
x + y
50-
}
51-
52-
blackhole.consume(result)
53-
}
54-
55-
@Benchmark
56-
fun arrowBindingFailure(blackhole: Blackhole) {
57-
val result: Either<Error, Int> = either {
58-
val x = arrowProvideX().bind()
59-
val z = arrowProvideZ().bind()
60-
x + z
61-
}
62-
63-
blackhole.consume(result)
64-
}
65-
66-
@Benchmark
67-
fun andThenSuccess(blackhole: Blackhole) {
68-
val result = provideX().andThen { x ->
69-
provideY().andThen { y ->
70-
Ok(x + y)
71-
}
72-
}
73-
74-
blackhole.consume(result)
75-
}
76-
77-
@Benchmark
78-
fun andThenFailure(blackhole: Blackhole) {
79-
val result = provideX().andThen { x ->
80-
provideZ().andThen { z ->
81-
Ok(x + z)
82-
}
83-
}
84-
85-
blackhole.consume(result)
86-
}
87-
88-
@Benchmark
89-
fun arrowFlatMapSuccess(blackhole: Blackhole) {
90-
val result = arrowProvideX().flatMap { x ->
91-
arrowProvideY().flatMap { y ->
92-
(x + y).right()
93-
}
94-
}
95-
96-
blackhole.consume(result)
97-
}
98-
99-
@Benchmark
100-
fun arrowFlatMapFailure(blackhole: Blackhole) {
101-
val result = arrowProvideX().flatMap { x ->
102-
arrowProvideZ().flatMap { z ->
103-
(x + z).right()
104-
}
105-
}
106-
107-
blackhole.consume(result)
108-
}
109-
11039
private object Error
11140

11241
private fun provideX(): Result<Int, Error> = Ok(1)
11342
private fun provideY(): Result<Int, Error> = Ok(2)
11443
private fun provideZ(): Result<Int, Error> = Err(Error)
115-
116-
private fun arrowProvideX(): Either<Error, Int> = 1.right()
117-
private fun arrowProvideY(): Either<Error, Int> = 2.right()
118-
private fun arrowProvideZ(): Either<Error, Int> = Error.left()
11944
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.github.michaelbull.result
2+
3+
import arrow.core.Either
4+
import arrow.core.flatMap
5+
import arrow.core.left
6+
import arrow.core.right
7+
import kotlinx.benchmark.Benchmark
8+
import kotlinx.benchmark.BenchmarkMode
9+
import kotlinx.benchmark.BenchmarkTimeUnit
10+
import kotlinx.benchmark.Blackhole
11+
import kotlinx.benchmark.Mode
12+
import kotlinx.benchmark.OutputTimeUnit
13+
import kotlinx.benchmark.Scope
14+
import kotlinx.benchmark.State
15+
16+
@State(Scope.Benchmark)
17+
@BenchmarkMode(Mode.Throughput)
18+
@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS)
19+
class ArrowBindingBenchmark {
20+
21+
@Benchmark
22+
fun arrowFlatMapSuccess(blackhole: Blackhole) {
23+
val result = arrowProvideX().flatMap { x ->
24+
arrowProvideY().flatMap { y ->
25+
(x + y).right()
26+
}
27+
}
28+
29+
blackhole.consume(result)
30+
}
31+
32+
@Benchmark
33+
fun arrowFlatMapFailure(blackhole: Blackhole) {
34+
val result = arrowProvideX().flatMap { x ->
35+
arrowProvideZ().flatMap { z ->
36+
(x + z).right()
37+
}
38+
}
39+
40+
blackhole.consume(result)
41+
}
42+
43+
private object Error
44+
45+
private fun arrowProvideX(): Either<Error, Int> = 1.right()
46+
private fun arrowProvideY(): Either<Error, Int> = 2.right()
47+
private fun arrowProvideZ(): Either<Error, Int> = Error.left()
48+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ktor-server-content-negotiation = { module = "io.ktor:ktor-server-content-negoti
3333
ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor" }
3434
logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
3535

36+
3637
[plugins]
3738
versions = { id = "com.github.ben-manes.versions", version.ref = "versions-plugin" }
3839

0 commit comments

Comments
 (0)