Skip to content

Commit

Permalink
reintroduce ox benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Oct 23, 2023
1 parent 664bed8 commit 7d36471
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
fetch-depth: 0
- uses: olafurpg/setup-scala@v13
with:
java-version: openjdk@1.17.0
java-version: openjdk@21.0.1=tgz+https://download.java.net/java/GA/jdk21.0.1/415e3f918a1f4062a0074a2794853d0d/12/GPL/openjdk-21.0.1_linux-x64_bin.tar.gz

- name: install async-profiler
run: |
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/readme.yml

This file was deleted.

12 changes: 7 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
val scala3Version = "3.3.0"
val scala3Version = "3.3.1"
val scala2Version = "2.13.12"

val compilerOptions = Seq(
Expand Down Expand Up @@ -237,13 +237,15 @@ lazy val `kyo-bench` =
.in(file("kyo-bench"))
.enablePlugins(JmhPlugin)
.dependsOn(`kyo-core-opt` % "test->test;compile->compile")
.dependsOn(`kyo-sttp`)
.dependsOn(`kyo-tapir`)
.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.12"
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"
)

lazy val rewriteReadmeFile = taskKey[Unit]("Rewrite README file")
Expand Down
32 changes: 16 additions & 16 deletions kyo-bench/src/main/scala/kyo/bench/BroadFlatMapBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ class BroadFlatMapBench extends Bench.SyncAndFork[BigInt] {
zioFib(depth)
}

// def oxFib(n: Int): BigInt =
// if (n <= 1) n
// else oxFib(n - 1) + oxFib(n - 2)

// @Benchmark
// def syncOx(): BigInt = {
// oxFib(depth)
// }

// @Benchmark
// def forkOx(): BigInt = {
// import ox._
// scoped {
// fork(oxFib(depth)).join()
// }
// }
def oxFib(n: Int): BigInt =
if (n <= 1) n
else oxFib(n - 1) + oxFib(n - 2)

@Benchmark
def syncOx(): BigInt = {
oxFib(depth)
}

@Benchmark
def forkOx(): BigInt = {
import ox._
scoped {
fork(oxFib(depth)).join()
}
}
}
32 changes: 16 additions & 16 deletions kyo-bench/src/main/scala/kyo/bench/ChainedForkBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ class ChainedForkBench extends Bench.ForkOnly[Int] {
} yield 0
}

// @Benchmark
// def forkOx() = {
// import ox._
// def iterate(p: CompletableFuture[Unit], n: Int): Unit =
// if (n <= 0) p.complete(())
// else
// scoped {
// fork(iterate(p, n - 1))
// }

// scoped {
// val p = new CompletableFuture[Unit]()
// fork(iterate(p, depth))
// p.get()
// }
// }
@Benchmark
def forkOx() = {
import ox._
def iterate(p: CompletableFuture[Unit], n: Int): Unit =
if (n <= 0) p.complete(())
else
scoped {
fork(iterate(p, n - 1))
}

scoped {
val p = new CompletableFuture[Unit]()
fork(iterate(p, depth))
p.get()
}
}
}
38 changes: 19 additions & 19 deletions kyo-bench/src/main/scala/kyo/bench/ForkManyBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ class ForkManyBench extends Bench.ForkOnly[Int] {
} yield 0
}

// @Benchmark
// def forkOx() = {
// import ox._
// import ox.channels._

// scoped {
// val promise = new CompletableFuture[Unit]
// val ref = new AtomicInteger(depth)
// for (_ <- 0 until depth) {
// fork {
// ref.decrementAndGet() match {
// case 1 => promise.complete(())
// case _ => ()
// }
// }
// }
// promise.get()
// }
// }
@Benchmark
def forkOx() = {
import ox._
import ox.channels._

scoped {
val promise = new CompletableFuture[Unit]
val ref = new AtomicInteger(depth)
for (_ <- 0 until depth) {
fork {
ref.decrementAndGet() match {
case 1 => promise.complete(())
case _ => ()
}
}
}
promise.get()
}
}
}
38 changes: 19 additions & 19 deletions kyo-bench/src/main/scala/kyo/bench/ProducerConsumerBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ class ProducerConsumerBench extends Bench.ForkOnly[Unit] {
}
}

// @Benchmark
// def forkOx() = {
// import ox._
// import ox.channels._

// val q = Channel[Unit](depth / 2)
// scoped {
// val f1 =
// fork {
// for (_ <- 0 until depth) q.send(()).orThrow
// }
// val f2 =
// fork {
// for (_ <- 0 until depth) q.take(1).drain()
// }
// f1.join()
// f2.join()
// }
// }
@Benchmark
def forkOx() = {
import ox._
import ox.channels._

val q = Channel[Unit](depth / 2)
scoped {
val f1 =
fork {
for (_ <- 0 until depth) q.send(()).orThrow
}
val f2 =
fork {
for (_ <- 0 until depth) q.take(1).drain()
}
f1.join()
f2.join()
}
}
}

0 comments on commit 7d36471

Please sign in to comment.