-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Signature of ForEach#collectM (#1236)
* update signature of foreach collectm * format
- Loading branch information
1 parent
82817cd
commit 14d825c
Showing
9 changed files
with
159 additions
and
41 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
benchmarks/src/main/scala/zio/prelude/CollectBenchmark.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,53 @@ | ||
package zio.prelude | ||
|
||
import cats.effect.unsafe.implicits.global | ||
import cats.effect.{IO => CIO} | ||
import cats.instances.list._ | ||
import cats.syntax.all._ | ||
import org.openjdk.jmh.annotations.{State => BenchmarkState, _} | ||
import org.openjdk.jmh.infra.Blackhole | ||
import zio.prelude.fx.ZPure | ||
import zio.{Scope => _, _} | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
@BenchmarkState(Scope.Thread) | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, timeUnit = TimeUnit.SECONDS, time = 3) | ||
@Warmup(iterations = 5, timeUnit = TimeUnit.SECONDS, time = 3) | ||
@Fork(value = 1) | ||
class CollectBenchmarks { | ||
|
||
var list: List[Int] = _ | ||
|
||
@Param(Array("100000")) | ||
var size: Int = _ | ||
|
||
@Setup(Level.Trial) | ||
def setup(): Unit = | ||
list = (1 to size).toList | ||
|
||
@Benchmark | ||
def catsTraverseFilterOption(bh: Blackhole): Unit = | ||
bh.consume(list.traverse(n => Option(Option(n)))) | ||
|
||
@Benchmark | ||
def catsTraverseFilterCIO(bh: Blackhole): Unit = | ||
bh.consume(list.traverseFilter(n => CIO.pure(Option(n))).unsafeRunSync()) | ||
|
||
@Benchmark | ||
def zioCollectMOption(bh: Blackhole): Unit = | ||
bh.consume(list.collectM(n => Option(Option(n)))) | ||
|
||
@Benchmark | ||
def zioCollectMZIO(bh: Blackhole): Unit = | ||
bh.consume(unsafeRun(list.collectM(n => ZIO.succeed(Option(n))))) | ||
|
||
@Benchmark | ||
def zioCollectMZPure(bh: Blackhole): Unit = | ||
bh.consume(list.collectM(n => ZPure.succeed[Unit, Option[Int]](Option(n))).run) | ||
|
||
def unsafeRun[E, A](zio: ZIO[Any, E, A]): A = | ||
Unsafe.unsafe(implicit unsafe => Runtime.default.unsafe.run(zio).getOrThrowFiberFailure()) | ||
} |
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
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
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
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
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
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
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
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