Last active
August 15, 2016 15:21
-
-
Save travisbrown/cf9697d33bd4ed8fa473ab46d4942e31 to your computer and use it in GitHub Desktop.
This file contains 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 cats.bench | |
import cats.data.Xor | |
import cats.instances.either._ | |
import cats.syntax.all._ | |
import org.openjdk.jmh.annotations.{ Benchmark, Scope, State } | |
@State(Scope.Benchmark) | |
class EitherBench { | |
val ea: Either[String, Int] = Right(1) | |
val eb: Either[String, Int] = Right(2) | |
val ec: Either[String, Int] = Right(3) | |
val xa: Xor[String, Int] = Xor.right(1) | |
val xb: Xor[String, Int] = Xor.right(2) | |
val xc: Xor[String, Int] = Xor.right(3) | |
@Benchmark def flatMapsEither(): Either[String, Int] = for { | |
a <- ea; b <- eb; c <- ec | |
} yield a + b + c | |
@Benchmark def flatMapsXor(): Xor[String, Int] = for { | |
a <- xa; b <- xb; c <- xc | |
} yield a + b + c | |
@Benchmark def cartesianEither(): Either[String, Int] = (ea |@| eb |@| ec).map(_ + _ + _) | |
@Benchmark def cartesianXor(): Xor[String, Int] = (xa |@| xb |@| xc).map(_ + _ + _) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Throughput:
And allocation rates:
On: