diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ArrayStackBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ArrayStackBenchmark.scala deleted file mode 100644 index a2cad2728..000000000 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ArrayStackBenchmark.scala +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* -package monix.benchmarks - -import java.util.concurrent.TimeUnit -import monix.execution.internal.collection.ArrayStack -import org.openjdk.jmh.annotations._ - -/** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark ArrayStackBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.ArrayStackBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ -@State(Scope.Thread) -@BenchmarkMode(Array(Mode.Throughput)) -@OutputTimeUnit(TimeUnit.SECONDS) -class ArrayStackBenchmark { - @Benchmark - def shallow(): Long = { - val stack = new ArrayStack[Int] - var idx = 0 - while (idx < 7) { - stack.push(idx) - idx += 1 - } - - var sum = 0L - while (!stack.isEmpty) sum += stack.pop() - sum - } - - @Benchmark - def deep(): Long = { - val stack = new ArrayStack[Int] - var idx = 0 - while (idx < 250) { - stack.push(idx) - idx += 1 - } - - var sum = 0L - while (!stack.isEmpty) sum += stack.pop() - sum - } -} - */ \ No newline at end of file diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapAccumulateBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapAccumulateBenchmark.scala index 6250a7eb6..292118765 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapAccumulateBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapAccumulateBenchmark.scala @@ -57,28 +57,28 @@ class ObservableMapAccumulateBenchmark { .runSyncUnsafe() } - @Benchmark - def fs2Stream() = { - FS2Stream - .emits(0 until n) - .mapAccumulate(0) { case (acc, i) => - val added = acc + i - (added, added) - } - .compile - .drain - } +// @Benchmark +// def fs2Stream() = { +// FS2Stream +// .emits(0 until n) +// .mapAccumulate(0) { case (acc, i) => +// val added = acc + i +// (added, added) +// } +// .compile +// .drain +// } - @Benchmark - def zioStream() = { - val stream = ZStream - .fromIterable(0 until n) - .mapAccum(0) { case (acc, i) => - val added = acc + i - (added, added) - } - .runDrain - - zioUntracedRuntime.unsafeRun(stream) - } +// @Benchmark +// def zioStream() = { +// val stream = ZStream +// .fromIterable(0 until n) +// .mapAccum(0) { case (acc, i) => +// val added = acc + i +// (added, added) +// } +// .runDrain +// +// zioUntracedRuntime.unsafeRun(stream) +// } } diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapTaskBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapTaskBenchmark.scala index e05ab9e22..34f050712 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapTaskBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapTaskBenchmark.scala @@ -15,7 +15,6 @@ * limitations under the License. */ -/* package monix.benchmarks import java.util.concurrent.TimeUnit @@ -49,7 +48,7 @@ import scala.concurrent.{Await, Promise} @OutputTimeUnit(TimeUnit.SECONDS) class ObservableMapTaskBenchmark { @Param(Array("10000")) - var size: Int = _ + var size: Long = _ @Benchmark def run(): Long = { @@ -77,4 +76,3 @@ class ObservableMapTaskBenchmark { Await.result(p.future, Duration.Inf) } } -*/ \ No newline at end of file diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskAttemptBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskAttemptBenchmark.scala index 487411be8..4ec33d9e0 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskAttemptBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskAttemptBenchmark.scala @@ -15,7 +15,6 @@ * limitations under the License. */ -/* package monix.benchmarks import java.util.concurrent.TimeUnit @@ -51,7 +50,7 @@ class TaskAttemptBenchmark { if (i < size) Task.pure(i + 1).attempt.flatMap(_.fold(Task.raiseError, loop)) else Task.pure(i) - Await.result(loop(0).runAsync, Duration.Inf) + Await.result(loop(0).runToFuture, Duration.Inf) } @Benchmark @@ -68,7 +67,6 @@ class TaskAttemptBenchmark { else Task.pure(i) - Await.result(loop(0).runAsync, Duration.Inf) + Await.result(loop(0).runToFuture, Duration.Inf) } } -*/ \ No newline at end of file diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskDeepBindBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskDeepBindBenchmark.scala index 4287d04b2..d86147387 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskDeepBindBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskDeepBindBenchmark.scala @@ -15,7 +15,6 @@ * limitations under the License. */ -/* package monix.benchmarks import java.util.concurrent.TimeUnit @@ -53,7 +52,7 @@ class TaskDeepBindBenchmark { _ <- if(j > size) Task.pure(j) else loop(j + 1) } yield j - Await.result(loop(0).runAsync, Duration.Inf) + Await.result(loop(0).runToFuture, Duration.Inf) } @Benchmark @@ -64,7 +63,7 @@ class TaskDeepBindBenchmark { _ <- if(j > size) Task.eval(j) else loop(j + 1) } yield j - Await.result(loop(0).runAsync, Duration.Inf) + Await.result(loop(0).runToFuture, Duration.Inf) } @Benchmark @@ -75,7 +74,6 @@ class TaskDeepBindBenchmark { _ <- if(j > size) Task.eval(j) else loop(j + 1) } yield j - Await.result(loop(0).runAsync, Duration.Inf) + Await.result(loop(0).runToFuture, Duration.Inf) } } -*/ \ No newline at end of file diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskHandleErrorBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskHandleErrorBenchmark.scala index 035f5291b..6b60accc1 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskHandleErrorBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskHandleErrorBenchmark.scala @@ -15,7 +15,6 @@ * limitations under the License. */ -/* package monix.benchmarks import java.util.concurrent.TimeUnit @@ -55,7 +54,7 @@ class TaskHandleErrorBenchmark { else Task.pure(i) - Await.result(loop(0).runAsync, Duration.Inf) + Await.result(loop(0).runToFuture, Duration.Inf) } @Benchmark @@ -71,7 +70,6 @@ class TaskHandleErrorBenchmark { else Task.pure(i) - Await.result(loop(0).runAsync, Duration.Inf) + Await.result(loop(0).runToFuture, Duration.Inf) } } -*/ \ No newline at end of file diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapCallsBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapCallsBenchmark.scala index 5f2d0014f..780404a2f 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapCallsBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapCallsBenchmark.scala @@ -15,7 +15,6 @@ * limitations under the License. */ -/* package monix.benchmarks import java.util.concurrent.TimeUnit @@ -71,4 +70,3 @@ object TaskMapCallsBenchmark { sum } } -*/ \ No newline at end of file diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapStreamBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapStreamBenchmark.scala index a5b1d0be0..48ff951ff 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapStreamBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapStreamBenchmark.scala @@ -15,7 +15,6 @@ * limitations under the License. */ -/* package monix.benchmarks import java.util.concurrent.TimeUnit @@ -64,7 +63,7 @@ object TaskMapStreamBenchmark { stream = mapStream(addOne)(stream) i += 1 } - Await.result(sum(0)(stream).runAsync, Duration.Inf) + Await.result(sum(0)(stream).runToFuture, Duration.Inf) } final case class Stream(value: Int, next: Task[Option[Stream]]) @@ -92,4 +91,3 @@ object TaskMapStreamBenchmark { Task.pure(acc) } } - */ \ No newline at end of file diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskSequenceBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskSequenceBenchmark.scala index 23c536a2e..df7ec8266 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskSequenceBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskSequenceBenchmark.scala @@ -64,26 +64,26 @@ class TaskSequenceBenchmark { val parallelism: Int = 10 - @Benchmark - def catsSequence(): Long = { - val tasks = (0 until count).map(_ => IO(1)).toList - val result = tasks.sequence.map(_.sum.toLong) - result.unsafeRunSync() - } - - @Benchmark - def catsParSequence(): Long = { - val tasks = (0 until count).map(_ => IO(1)).toList - val result = tasks.parSequence.map(_.sum.toLong) - result.unsafeRunSync() - } - - @Benchmark - def catsParSequenceN(): Long = { - val tasks = (0 until count).map(_ => IO(1)).toList - val result = tasks.parSequenceN(parallelism.toLong).map(_.sum.toLong) - result.unsafeRunSync() - } +// @Benchmark +// def catsSequence(): Long = { +// val tasks = (0 until count).map(_ => IO(1)).toList +// val result = tasks.sequence.map(_.sum.toLong) +// result.unsafeRunSync() +// } + +// @Benchmark +// def catsParSequence(): Long = { +// val tasks = (0 until count).map(_ => IO(1)).toList +// val result = tasks.parSequence.map(_.sum.toLong) +// result.unsafeRunSync() +// } + +// @Benchmark +// def catsParSequenceN(): Long = { +// val tasks = (0 until count).map(_ => IO(1)).toList +// val result = tasks.parSequenceN(parallelism.toLong).map(_.sum.toLong) +// result.unsafeRunSync() +// } @Benchmark def monixSequence(): Long = { @@ -115,32 +115,32 @@ class TaskSequenceBenchmark { result.runSyncUnsafe() } - @Benchmark - def zioSequence(): Long = { - val tasks = (0 until count).map(_ => ZIO.effectTotal(1)).toList - val result = ZIO.collectAll(tasks).map(_.sum.toLong) - zioUntracedRuntime.unsafeRun(result) - } - - @Benchmark - def zioParSequence(): Long = { - val tasks = (0 until count).map(_ => ZIO.effectTotal(1)).toList - val result = ZIO.collectAllPar(tasks).map(_.sum.toLong) - zioUntracedRuntime.unsafeRun(result) - } - - @Benchmark - def zioParSequenceN(): Long = { - val tasks = (0 until count).map(_ => ZIO.effectTotal(1)).toList - val result = ZIO.collectAllParN(parallelism)(tasks).map(_.sum.toLong) - zioUntracedRuntime.unsafeRun(result) - } - - @Benchmark - def futureSequence(): Long = { - val futures = (0 until count).map(_ => Future(1)).toList - val f: Future[Long] = Future.sequence(futures).map(_.sum.toLong) - Await.result(f, Duration.Inf) - } - -} \ No newline at end of file +// @Benchmark +// def zioSequence(): Long = { +// val tasks = (0 until count).map(_ => ZIO.effectTotal(1)).toList +// val result = ZIO.collectAll(tasks).map(_.sum.toLong) +// zioUntracedRuntime.unsafeRun(result) +// } + +// @Benchmark +// def zioParSequence(): Long = { +// val tasks = (0 until count).map(_ => ZIO.effectTotal(1)).toList +// val result = ZIO.collectAllPar(tasks).map(_.sum.toLong) +// zioUntracedRuntime.unsafeRun(result) +// } + +// @Benchmark +// def zioParSequenceN(): Long = { +// val tasks = (0 until count).map(_ => ZIO.effectTotal(1)).toList +// val result = ZIO.collectAllParN(parallelism)(tasks).map(_.sum.toLong) +// zioUntracedRuntime.unsafeRun(result) +// } + +// @Benchmark +// def futureSequence(): Long = { +// val futures = (0 until count).map(_ => Future(1)).toList +// val f: Future[Long] = Future.sequence(futures).map(_.sum.toLong) +// Await.result(f, Duration.Inf) +// } + +} diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShallowBindBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShallowBindBenchmark.scala index e5cea724d..855e8b90e 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShallowBindBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShallowBindBenchmark.scala @@ -15,7 +15,6 @@ * limitations under the License. */ -/* package monix.benchmarks import java.util.concurrent.TimeUnit @@ -79,4 +78,3 @@ class TaskShallowBindBenchmark { Await.result(task.runToFuture, Duration.Inf) } } -*/ \ No newline at end of file diff --git a/benchmarks/vnext/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala similarity index 99% rename from benchmarks/vnext/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala rename to benchmarks/shared/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala index da576a660..52dccffcb 100644 --- a/benchmarks/vnext/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala @@ -17,10 +17,11 @@ package monix.benchmarks -import java.util.concurrent.TimeUnit import monix.eval.Task import monix.execution.Cancelable import org.openjdk.jmh.annotations._ + +import java.util.concurrent.TimeUnit import scala.concurrent.Await import scala.concurrent.duration.Duration diff --git a/benchmarks/vprev/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala b/benchmarks/vprev/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala deleted file mode 100644 index 7f8fe311a..000000000 --- a/benchmarks/vprev/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* -package monix.benchmarks - -import java.util.concurrent.TimeUnit -import monix.eval.Task -import monix.execution.Cancelable -import scala.util.control.NonFatal -import org.openjdk.jmh.annotations._ -import scala.concurrent.Await -import scala.concurrent.duration.Duration - -/** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark TaskShiftBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskShiftBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ -@State(Scope.Thread) -@BenchmarkMode(Array(Mode.Throughput)) -@OutputTimeUnit(TimeUnit.SECONDS) -class TaskShiftBenchmark { - @Param(Array("3000")) - var size: Int = _ - - @Benchmark - def trampolinedShift1(): Int = { - def loop(i: Int): Task[Int] = - if (i < size) - TaskShiftBenchmark.trampolinedShift1.map(_ => i + 1).flatMap(loop) - else - Task.pure(i) - - val task = Task.pure(0).flatMap(loop) - Await.result(task.runAsync, Duration.Inf) - } - - @Benchmark - def trampolinedShift2(): Int = { - def loop(i: Int): Task[Int] = - if (i < size) - TaskShiftBenchmark.trampolinedShift2.map(_ => i + 1).flatMap(loop) - else - Task.pure(i) - - val task = Task.pure(0).flatMap(loop) - Await.result(task.runAsync, Duration.Inf) - } - - @Benchmark - def forkedShift(): Int = { - def loop(i: Int): Task[Int] = - if (i < size) - Task.shift.map(_ => i + 1).flatMap(loop) - else - Task.pure(i) - - val task = Task.pure(0).flatMap(loop) - Await.result(task.runAsync, Duration.Inf) - } - - @Benchmark - def lightAsync(): Int = { - def loop(i: Int): Task[Int] = - if (i < size) - TaskShiftBenchmark.async[Int](_.onSuccess(i + 1)).flatMap(loop) - else - Task.pure(i) - - val task = Task.pure(0).flatMap(loop) - Await.result(task.runAsync, Duration.Inf) - } - - @Benchmark - def executeWithOptions(): Int = { - def loop(i: Int): Task[Int] = - if (i < size) - Task.now(i + 1).executeWithOptions(x => x).flatMap(loop) - else - Task.pure(i) - - val task = Task.pure(0).flatMap(loop) - Await.result(task.runAsync, Duration.Inf) - } - - - @Benchmark - def createNonCancelable(): Int = { - def loop(i: Int): Task[Int] = - if (i < size) - Task.create[Int] { (_, cb) => cb.onSuccess(i + 1); Cancelable.empty }.flatMap(loop) - else - Task.pure(i) - - val task = Task.pure(0).flatMap(loop) - Await.result(task.runAsync, Duration.Inf) - } - - @Benchmark - def createCancelable(): Int = { - def loop(i: Int): Task[Int] = - if (i < size) - Task.create[Int] { (_, cb) => cb.onSuccess(i + 1); Cancelable(() => {}) }.flatMap(loop) - else - Task.pure(i) - - val task = Task.pure(0).flatMap(loop) - Await.result(task.runAsync, Duration.Inf) - } -} - -object TaskShiftBenchmark { - import monix.execution.Callback - - def async[A](k: Callback[Throwable, A] => Unit): Task[A] = - Task.unsafeCreate { (ctx, cb) => - try k(Callback.async(cb)(ctx.scheduler)) catch { - case ex if NonFatal(ex) => - // We cannot stream the error, because the callback might have - // been called already and we'd be violating its contract, - // hence the only thing possible is to log the error. - ctx.scheduler.reportFailure(ex) - } - } - - val trampolinedShift1: Task[Unit] = - async(_.onSuccess(())) - - val trampolinedShift2: Task[Unit] = - Task.unsafeCreate { (ctx, cb) => - ctx.scheduler.executeTrampolined(() => cb.onSuccess(())) - } -} - */ \ No newline at end of file