forked from typelevel/cats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmarks for collectFirst on Chain
- Loading branch information
Showing
2 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
bench/src/main/scala/cats/bench/ChainCollectFirstBench.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package cats.bench | ||
|
||
import cats.Foldable | ||
import cats.data.Chain | ||
import org.openjdk.jmh.annotations.{Benchmark, Scope, State} | ||
|
||
@State(Scope.Thread) | ||
class ChainCollectFirstBench { | ||
|
||
private val foldableChain = Foldable[Chain] | ||
|
||
private val small = Chain(1, 2, 3, 4, 5) | ||
private val smallLast = 5 | ||
|
||
private val medium = (0 to 10) | ||
.foldLeft(Chain.empty[Int])((acc, _) => acc ++ Chain.fromSeq(0 to 10)) | ||
private val mediumLast = 10 * 10 | ||
|
||
private val large = (0 to 1000) | ||
.foldLeft(Chain.empty[Int])((acc, _) => acc ++ Chain.fromSeq(0 to 1000)) | ||
private val largeLast = 1000 * 1000 | ||
|
||
@Benchmark | ||
def collectFirstSmallNew: Option[Int] = small.collectFirst { | ||
case x if x == smallLast => x | ||
} | ||
|
||
@Benchmark | ||
def collectFirstSmallFoldable: Option[Int] = foldableChain.collectFirst(small) { | ||
case x if x == smallLast => x | ||
} | ||
|
||
@Benchmark | ||
def collectFirstMediumNew: Option[Int] = medium.collectFirst { | ||
case x if x == mediumLast => x | ||
} | ||
|
||
@Benchmark | ||
def collectFirstMediumFoldable: Option[Int] = foldableChain.collectFirst(medium) { | ||
case x if x == mediumLast => x | ||
} | ||
|
||
@Benchmark | ||
def collectFirstLargeNew: Option[Int] = medium.collectFirst { | ||
case x if x == largeLast => x | ||
} | ||
|
||
@Benchmark | ||
def collectFirstLargeFoldable: Option[Int] = foldableChain.collectFirst(medium) { | ||
case x if x == largeLast => x | ||
} | ||
|
||
|
||
|
||
@Benchmark | ||
def collectFirstSomeSmallNew: Option[Int] = small.collectFirstSome { | ||
case x if x == smallLast => Some(x) | ||
case _ => None | ||
} | ||
|
||
@Benchmark | ||
def collectFirstSome2SmallNew: Option[Int] = small.collectFirstSome2 { | ||
case x if x == smallLast => Some(x) | ||
case _ => None | ||
} | ||
|
||
@Benchmark | ||
def collectFirstSomeSmallFoldable: Option[Int] = foldableChain.collectFirstSome(small) { | ||
case x if x == smallLast => Some(x) | ||
case _ => None | ||
} | ||
|
||
@Benchmark | ||
def collectFirstSomeMediumNew: Option[Int] = medium.collectFirstSome { | ||
case x if x == mediumLast => Some(x) | ||
case _ => None | ||
} | ||
|
||
@Benchmark | ||
def collectFirstSome2MediumNew: Option[Int] = medium.collectFirstSome2 { | ||
case x if x == mediumLast => Some(x) | ||
case _ => None | ||
} | ||
|
||
@Benchmark | ||
def collectFirstSomeMediumFoldable: Option[Int] = foldableChain.collectFirstSome(medium) { | ||
case x if x == mediumLast => Some(x) | ||
case _ => None | ||
} | ||
|
||
@Benchmark | ||
def collectFirstSomeLargeNew: Option[Int] = medium.collectFirstSome { | ||
case x if x == largeLast => Some(x) | ||
case _ => None | ||
} | ||
|
||
@Benchmark | ||
def collectFirstSome2LargeNew: Option[Int] = medium.collectFirstSome2 { | ||
case x if x == largeLast => Some(x) | ||
case _ => None | ||
} | ||
|
||
@Benchmark | ||
def collectFirstSomeLargeFoldable: Option[Int] = foldableChain.collectFirstSome(medium) { | ||
case x if x == largeLast => Some(x) | ||
case _ => None | ||
} | ||
} |
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