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

Add NonEmptyChain #2406

Merged
merged 23 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add chain benchmarks
  • Loading branch information
Luka Jacobowitz committed Aug 8, 2018
commit 0c4cc5d53e5aafc986450d5003c4628905e9865d
6 changes: 0 additions & 6 deletions bench/src/main/scala/cats/bench/CatenableBench.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cats.bench

import cats.data.Catenable
import cats.implicits._

import org.openjdk.jmh.annotations.{Benchmark, Scope, State}

@State(Scope.Thread)
Expand Down Expand Up @@ -47,8 +45,4 @@ class CatenableBenchmark {
@Benchmark def createSmallCatenable: Catenable[Int] = Catenable(1, 2, 3, 4, 5)
@Benchmark def createSmallVector: Vector[Int] = Vector(1, 2, 3, 4, 5)
@Benchmark def createSmallList: List[Int] = List(1, 2, 3, 4, 5)

@Benchmark def accumulateCatenable: Catenable[Int] = largeList.foldMap(Catenable.singleton)
@Benchmark def accumulateVector: Vector[Int] = largeList.foldMap(Vector(_))
@Benchmark def accumulateList: List[Int] = largeList.foldMap(List(_))
}
24 changes: 24 additions & 0 deletions bench/src/main/scala/cats/bench/CollectionMonoidBench.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cats.bench

import cats.Monoid
import cats.data.Catenable
import cats.implicits._
import chain.Chain
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}

@State(Scope.Thread)
class CollectionMonoidBench {

private val largeList = (0 to 1000000).toList

implicit def monoidChain[A]: Monoid[Chain[A]] = new Monoid[Chain[A]] {
def empty: Chain[A] = Chain.empty[A]

def combine(x: Chain[A], y: Chain[A]): Chain[A] = x ++ y
}

@Benchmark def accumulateCatenable: Catenable[Int] = largeList.foldMap(Catenable.singleton)
@Benchmark def accumulateVector: Vector[Int] = largeList.foldMap(Vector(_))
@Benchmark def accumulateList: List[Int] = largeList.foldMap(List(_))
@Benchmark def accumulateChain: Chain[Int] = largeList.foldMap(Chain.single)
}
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ lazy val bench = project.dependsOn(macrosJVM, coreJVM, freeJVM, lawsJVM)
.settings(commonJvmSettings)
.settings(coverageEnabled := false)
.settings(libraryDependencies ++= Seq(
"org.scalaz" %% "scalaz-core" % "7.2.23"))
"org.scalaz" %% "scalaz-core" % "7.2.23",
"org.spire-math" %% "chain" % "0.3.0"
))
.enablePlugins(JmhPlugin)

// cats-js is JS-only
Expand Down