zio-ubench


License

License

GroupId

GroupId

dev.koubic
ArtifactId

ArtifactId

zio-ubench_2.13
Last Version

Last Version

0.2.3
Release Date

Release Date

Type

Type

jar
Description

Description

zio-ubench
zio-ubench
Project URL

Project URL

https://github.com/jan-kouba/zio-ubench
Project Organization

Project Organization

dev.koubic
Source Code Management

Source Code Management

https://github.com/jan-kouba/zio-ubench

Download zio-ubench_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/dev.koubic/zio-ubench_2.13/ -->
<dependency>
    <groupId>dev.koubic</groupId>
    <artifactId>zio-ubench_2.13</artifactId>
    <version>0.2.3</version>
</dependency>
// https://jarcasting.com/artifacts/dev.koubic/zio-ubench_2.13/
implementation 'dev.koubic:zio-ubench_2.13:0.2.3'
// https://jarcasting.com/artifacts/dev.koubic/zio-ubench_2.13/
implementation ("dev.koubic:zio-ubench_2.13:0.2.3")
'dev.koubic:zio-ubench_2.13:jar:0.2.3'
<dependency org="dev.koubic" name="zio-ubench_2.13" rev="0.2.3">
  <artifact name="zio-ubench_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='dev.koubic', module='zio-ubench_2.13', version='0.2.3')
)
libraryDependencies += "dev.koubic" % "zio-ubench_2.13" % "0.2.3"
[dev.koubic/zio-ubench_2.13 "0.2.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.5
dev.zio : zio_2.13 jar 1.0.7

test (2)

Group / Artifact Type Version
dev.zio : zio-test_2.13 jar 1.0.7
dev.zio : zio-test-sbt_2.13 jar 1.0.7

Project Modules

There are no modules declared in this project.

zio-ubench

Release Artifacts Snapshot Artifacts

Micro-benchmark your ZIO effects!

// build.sbt
libraryDependencies += "dev.koubic" %% "zio-ubench" % "0.2.3"

How does it work?

import zio.ubench._
import zio._
import zio.duration._

val io = ZIO.effectTotal {
  (0 until 1000000)
    .map(_ + 1)
    .last
}

val ioDur = io.benchmark()

ioDur.flatMap { d =>
  console.putStrLn(s"duration of execution of io: ${d}")
}

Outputs:

duration of execution of io: PT0.02105794S

The benchmark() method accepts the parameter that describes how to do the benchmark:

val ioDur = io.benchmark(
  Benchmark.untilLocalDurationMin(30)
)

This stops the benchmark after the run time of the io was not improved for 30 steps.

We can also require the benchmark to run for at least 1 second:

val ioDur = io.benchmark(
  Benchmark.untilLocalDurationMin(30) <& Benchmark.untilTotalDuration(1.second)
)

We can also stop the benchmark if NRMSE is low and return the minimal run time observed:

val ioDur = io.benchmark(
  (
    (Benchmark.untilLocalDurationMin(30) <& Benchmark.untilTotalDuration(1.second)) ||
    Benchmark.untilLowNrmse(0.05, 10)
  ) &> Benchmark.minMeasurementDuration
)

We can also preheat the effect by running it for 1 second and then use the minimal run time from the pre-heat phase to calculate the number of repetitions of the effect, so that it runs approximately 50 milliseconds and then benchmark the repeated effect:

val ioDur = io.benchmark(
  (
    (
      (Benchmark.untilLocalDurationMin(30) <& Benchmark.untilTotalDuration(1.second)) ||
        Benchmark.untilLowNrmse(0.05, 10)
    ) &> Benchmark.minMeasurementDuration
  ).withPreheat(Benchmark.untilTotalDuration(100.millis), 50.millis)
)

See test/scala/example/ directory for examples.

For more details see the scaladoc of the Benchmark class.

Versions

Version
0.2.3