Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler warnings in 'bench' module #562

Merged
merged 6 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)
}
Expand Down
19 changes: 10 additions & 9 deletions bench/src/main/scala-2/cats/collections/bench/DietAddBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -53,7 +54,7 @@ class BestCaseRangesList {
}

@Setup
def setup: Unit = {
def setup(): Unit = {
scalazRanges = getBestCaseDataScalaz
dogRanges = getBestCaseDataDogs

Expand All @@ -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)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
Expand Down
8 changes: 3 additions & 5 deletions bench/src/main/scala-2/cats/collections/bench/HeapBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes "implicit numeric widening"

if (cnt <= 0) v
else loop(cnt - 1, v)
}
Expand Down