From 01407b351bb2a97f071ac68c8fa42a264ef8bcc8 Mon Sep 17 00:00:00 2001 From: Flavio Brasil Date: Sat, 2 Dec 2023 02:57:31 -0800 Subject: [PATCH] logging benchmark --- build.sbt | 14 +++-- .../main/scala/kyo/bench/LoggingBench.scala | 51 +++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 kyo-bench/src/main/scala/kyo/bench/LoggingBench.scala diff --git a/build.sbt b/build.sbt index 5658b375e..0c099d723 100644 --- a/build.sbt +++ b/build.sbt @@ -281,11 +281,15 @@ lazy val `kyo-bench` = .settings( `kyo-settings`, `without-cross-scala`, - libraryDependencies += "org.typelevel" %% "cats-effect" % "3.5.2", - libraryDependencies += "dev.zio" %% "zio" % zioVersion, - libraryDependencies += "dev.zio" %% "zio-concurrent" % zioVersion, - libraryDependencies += "com.softwaremill.ox" %% "core" % "0.0.14", - libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.16" % Test + libraryDependencies += "org.typelevel" %% "cats-effect" % "3.5.2", + libraryDependencies += "org.typelevel" %% "log4cats-core" % "2.6.0", + libraryDependencies += "org.typelevel" %% "log4cats-slf4j" % "2.6.0", + libraryDependencies += "dev.zio" %% "zio-logging" % "2.1.16", + libraryDependencies += "dev.zio" %% "zio-logging-slf4j2" % "2.1.16", + libraryDependencies += "dev.zio" %% "zio" % zioVersion, + libraryDependencies += "dev.zio" %% "zio-concurrent" % zioVersion, + libraryDependencies += "com.softwaremill.ox" %% "core" % "0.0.14", + libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.16" % Test ) lazy val rewriteReadmeFile = taskKey[Unit]("Rewrite README file") diff --git a/kyo-bench/src/main/scala/kyo/bench/LoggingBench.scala b/kyo-bench/src/main/scala/kyo/bench/LoggingBench.scala new file mode 100644 index 000000000..53d0bb069 --- /dev/null +++ b/kyo-bench/src/main/scala/kyo/bench/LoggingBench.scala @@ -0,0 +1,51 @@ +package kyo.bench + +class LoggingBench extends Bench.SyncAndFork[Unit] { + + val depth = 10000 + + def kyoBench() = { + import kyo._ + import kyo.ios._ + import kyo.logs._ + def loop(i: Int): Unit > IOs = + if (i > depth) + () + else + Logs.error("test").flatMap { _ => + loop(i + 1) + } + loop(0) + } + + def catsBench() = { + import cats.effect._ + import org.typelevel.log4cats.slf4j.Slf4jLogger + import cats.effect.unsafe.implicits.global + + val logger = Slf4jLogger.create[IO].unsafeRunSync() + + def loop(i: Int): IO[Unit] = + if (i > depth) + IO.unit + else + logger.error("test").flatMap { _ => + loop(i + 1) + } + loop(0) + } + + def zioBench() = { + import zio._ + import zio.logging.backend.SLF4J + + def loop(i: Int): UIO[Unit] = + if (i > depth) + ZIO.unit + else + ZIO.logError("test").flatMap { _ => + loop(i + 1) + } + loop(0).provide(Runtime.removeDefaultLoggers) + } +}