From 3249da1d39fab6de3ca919ee2359665dc74e780a Mon Sep 17 00:00:00 2001 From: satorg Date: Sun, 13 Nov 2022 19:43:38 -0800 Subject: [PATCH 1/6] fix in DietAddBench.scala --- .../cats/collections/bench/DietAddBench.scala | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/bench/src/main/scala-2/cats/collections/bench/DietAddBench.scala b/bench/src/main/scala-2/cats/collections/bench/DietAddBench.scala index 2b93eb20..f175888a 100644 --- a/bench/src/main/scala-2/cats/collections/bench/DietAddBench.scala +++ b/bench/src/main/scala-2/cats/collections/bench/DietAddBench.scala @@ -22,10 +22,11 @@ package cats.collections package bench -import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, Setup, State} -import scala.util.Random -import scalaz.{Diev, Enum, IList, Monoid, Show} -import cats._ +import org.openjdk.jmh.annotations._ +import scalaz.Diev +import scalaz.Enum +import scalaz.Monoid +import scalaz.Show @State(Scope.Thread) class BestCaseRangesList { @@ -53,7 +54,7 @@ class BestCaseRangesList { } @Setup - def setup: Unit = { + def setup(): Unit = { scalazRanges = getBestCaseDataScalaz dogRanges = getBestCaseDataDogs @@ -68,24 +69,24 @@ class DietAddBench extends BestCaseRangesList { implicit val scalazEnumInt: Monoid[Int] with Enum[Int] with Show[Int] = scalaz.std.anyVal.intInstance @Benchmark - def dogsDietAdd: Unit = { + def dogsDietAdd(): Unit = { var diet = Diet.empty[Int] dogValues.foreach { i => diet = diet + i } } @Benchmark - def scalazDievAdd: Unit = { + def scalazDievAdd(): Unit = { scalazValues.foldLeft(Diev.empty[Int])((d, r) => d + r) } @Benchmark - def dogsDietAddRange: Unit = { + def dogsDietAddRange(): Unit = { dogRanges.foldLeft(Diet.empty[Int])((d, r) => d + Range(r.start, r.end)) } @Benchmark - def scalazDievAddRange: Unit = { + def scalazDievAddRange(): Unit = { scalazRanges.foldLeft(Diev.empty[Int])((d, r) => d + ((r.start, r.end))) } } From da214c7d98d9b4f18fa8fcfe20fae3598b19029e Mon Sep 17 00:00:00 2001 From: satorg Date: Sun, 13 Nov 2022 19:49:55 -0800 Subject: [PATCH 2/6] fix in TreeListBench.scala --- .../scala-2/cats/collections/bench/TreeListBench.scala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bench/src/main/scala-2/cats/collections/bench/TreeListBench.scala b/bench/src/main/scala-2/cats/collections/bench/TreeListBench.scala index d1f353b9..e4f70048 100644 --- a/bench/src/main/scala-2/cats/collections/bench/TreeListBench.scala +++ b/bench/src/main/scala-2/cats/collections/bench/TreeListBench.scala @@ -22,10 +22,8 @@ package cats.collections package bench -import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, Setup, State} +import org.openjdk.jmh.annotations._ import org.openjdk.jmh.infra.Blackhole -import scala.util.Random -import cats._ import scala.annotation.tailrec @@ -39,7 +37,7 @@ class TreeListBench { var vect: Vector[Int] = _ @Setup - def setup: Unit = { + def setup(): Unit = { list = (0 until n).toList treeList = TreeList.fromList(list) vect = list.toVector @@ -116,7 +114,7 @@ class TreeListBench { val rand = new java.util.Random(42) @tailrec def loop(cnt: Int, acc: Int): Int = { - val v = treeList.getUnsafe((rand.nextInt() & Int.MaxValue) % n) + acc + val v = treeList.getUnsafe((rand.nextInt() & Int.MaxValue).toLong % n) + acc if (cnt <= 0) v else loop(cnt - 1, v) } From adb4830bd894b8f21025b6ee6fe201a41ac63835 Mon Sep 17 00:00:00 2001 From: satorg Date: Sun, 13 Nov 2022 19:57:38 -0800 Subject: [PATCH 3/6] fix in DietBenchSearch.scala --- .../collections/bench/DietBenchSearch.scala | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bench/src/main/scala-2/cats/collections/bench/DietBenchSearch.scala b/bench/src/main/scala-2/cats/collections/bench/DietBenchSearch.scala index 4994a2f7..cfe65f52 100644 --- a/bench/src/main/scala-2/cats/collections/bench/DietBenchSearch.scala +++ b/bench/src/main/scala-2/cats/collections/bench/DietBenchSearch.scala @@ -22,22 +22,24 @@ package cats.collections package bench -import org.openjdk.jmh.annotations.{Benchmark, Scope, Setup, State} +import org.openjdk.jmh.annotations._ +import scalaz.Diev +import scalaz.Enum +import scalaz.Monoid +import scalaz.Show import scala.util.Random -import scalaz.{Diev, Enum, Monoid, Show} -import cats._ @State(Scope.Benchmark) class DietBenchSearch { implicit val scalazEnumInt: Monoid[Int] with Enum[Int] with Show[Int] = scalaz.std.anyVal.intInstance - var diet = Diet.empty[Int] - var diev = Diev.empty[Int] + var diet: Diet[Int] = Diet.empty[Int] + var diev: Diev[Int] = Diev.empty[Int] @Setup - def setup: Unit = { + def setup(): Unit = { var i = 0 while (i < 1000) { val s = Random.nextInt() @@ -51,12 +53,12 @@ class DietBenchSearch { } @Benchmark - def dogsDietSearch: Unit = { + def dogsDietSearch(): Unit = { scala.Range(0, 1000).foreach(i => diet.contains(i)) } @Benchmark - def scalazDievSearch: Unit = { + def scalazDievSearch(): Unit = { scala.Range(0, 1000).foreach(i => diev.contains(i)) } } From 820c0bfdd442cb14698040024a78279cd1394605 Mon Sep 17 00:00:00 2001 From: satorg Date: Sun, 13 Nov 2022 19:59:21 -0800 Subject: [PATCH 4/6] fix in BigNumberLists.scala --- .../bench/{bignumbers.scala => BigNumberLists.scala} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename bench/src/main/scala-2/cats/collections/bench/{bignumbers.scala => BigNumberLists.scala} (93%) diff --git a/bench/src/main/scala-2/cats/collections/bench/bignumbers.scala b/bench/src/main/scala-2/cats/collections/bench/BigNumberLists.scala similarity index 93% rename from bench/src/main/scala-2/cats/collections/bench/bignumbers.scala rename to bench/src/main/scala-2/cats/collections/bench/BigNumberLists.scala index 2413bb86..fc5a8a41 100644 --- a/bench/src/main/scala-2/cats/collections/bench/bignumbers.scala +++ b/bench/src/main/scala-2/cats/collections/bench/BigNumberLists.scala @@ -22,8 +22,8 @@ package cats.collections package bench +import org.openjdk.jmh.annotations._ import scalaz.IList -import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, Setup, State} trait BigNumberLists { @Param(Array("10", "100", "1000", "10000")) @@ -33,7 +33,7 @@ trait BigNumberLists { var scalazlst: IList[Int] = _ @Setup - def setup: Unit = { + def setup(): Unit = { scala = (1 to n).toList scalazlst = IList.fromSeq(1 to n) } From 7767823e6de459ffec5d381a3506b0eab6ee053b Mon Sep 17 00:00:00 2001 From: satorg Date: Sun, 13 Nov 2022 20:00:54 -0800 Subject: [PATCH 5/6] fix in DietRandomizeBench.scala --- .../collections/bench/DietRandomizeBench.scala | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bench/src/main/scala-2/cats/collections/bench/DietRandomizeBench.scala b/bench/src/main/scala-2/cats/collections/bench/DietRandomizeBench.scala index 389187c0..62d78917 100644 --- a/bench/src/main/scala-2/cats/collections/bench/DietRandomizeBench.scala +++ b/bench/src/main/scala-2/cats/collections/bench/DietRandomizeBench.scala @@ -22,10 +22,13 @@ package cats.collections package bench -import org.openjdk.jmh.annotations.{Benchmark, Scope, State} +import org.openjdk.jmh.annotations._ +import scalaz.Diev +import scalaz.Enum +import scalaz.Monoid +import scalaz.Show + import scala.util.Random -import scalaz.{Diev, Enum, Monoid, Show} -import cats._ /** * In reality, no one uses the best and worst scenario, so this is a complete randomized benchmark @@ -38,22 +41,22 @@ class DietRandomizeBench extends BigNumberLists { implicit val scalazEnumInt: Monoid[Int] with Enum[Int] with Show[Int] = scalaz.std.anyVal.intInstance @Benchmark - def dogsDietAddRandom: Unit = { + def dogsDietAddRandom(): Unit = { Random.shuffle(scala).foldLeft(Diet.empty[Int])((d, r) => d + r) } @Benchmark - def scalazDievAddRandom: Unit = { + def scalazDievAddRandom(): Unit = { Random.shuffle(scalazlst.toList).foldLeft(Diev.empty[Int])((d, r) => d + r) } @Benchmark - def dogsDietAddRangeRandom: Unit = { + def dogsDietAddRangeRandom(): Unit = { Random.shuffle(scala).foldLeft(Diet.empty[Int])((d, r) => d + Range(r, r + 10)) } @Benchmark - def scalazDievAddRangeRandom: Unit = { + def scalazDievAddRangeRandom(): Unit = { var diev = Diev.empty[Int] Random.shuffle(scalazlst.toList).foldLeft(Diev.empty[Int])((d, r) => d + ((r, r + 10))) From eed2951a4be0380da73d474b8072f9aea584c5c1 Mon Sep 17 00:00:00 2001 From: satorg Date: Sun, 13 Nov 2022 20:01:53 -0800 Subject: [PATCH 6/6] fix in HeapBench.scala --- .../main/scala-2/cats/collections/bench/HeapBench.scala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bench/src/main/scala-2/cats/collections/bench/HeapBench.scala b/bench/src/main/scala-2/cats/collections/bench/HeapBench.scala index 4e206cd5..50b962f9 100644 --- a/bench/src/main/scala-2/cats/collections/bench/HeapBench.scala +++ b/bench/src/main/scala-2/cats/collections/bench/HeapBench.scala @@ -22,12 +22,10 @@ package cats.collections package bench -import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, Setup, State} +import org.openjdk.jmh.annotations._ import org.openjdk.jmh.infra.Blackhole -import scala.util.Random -import cats._ -import scala.annotation.tailrec +import scala.util.Random /** * run using, e.g. bench/jmh:run -i 3 -wi 3 -f1 -t1 .*HeapBench.* @@ -42,7 +40,7 @@ class HeapBench { var pheap: PairingHeap[Int] = _ @Setup - def setup: Unit = { + def setup(): Unit = { val rng = new Random(n) data = (0 until n).iterator.map(_ => rng.nextInt()).toArray heap = data.foldLeft(Heap.empty[Int])(_.add(_))