-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpure.scala
More file actions
35 lines (27 loc) · 913 Bytes
/
pure.scala
File metadata and controls
35 lines (27 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package matterhorn
package bench
import org.openjdk.jmh.annotations.{Benchmark, BenchmarkMode, Fork, Mode}
import IO._
import RTS.defaultRTS.{unsafePerformIO_ => run}
@Fork(1)
@BenchmarkMode(Array(Mode.Throughput))
class PureBenchmark {
def maps(size: Int): Unit = {
def f(io: IO[Unit])(n: Int): IO[Unit] = if (n == 0) io else f(io.map(_ => ()))(n - 1)
run(f(unitIO)(size))
}
def aps(size: Int): Unit = {
def f(n: Int): IO[Unit] = if (n == 0) unitIO else unitIO *> f(n - 1)
run(f(size))
}
def mapsandaps(size: Int): Unit = {
def f(n: Int): IO[Unit] = if (n == 0) unitIO.map(_ => ()) else unitIO.map(_ => ()) *> f(n - 1)
run(f(size))
}
@Benchmark def maps64 = maps(64)
@Benchmark def aps64 = maps(64)
@Benchmark def mapsandaps64 = maps(64)
@Benchmark def maps1024 = maps(1024)
@Benchmark def aps1024 = maps(1024)
@Benchmark def mapsandaps1024 = maps(1024)
}