Skip to content

Commit

Permalink
Use jmh-sbt over scaliper for benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers committed Aug 24, 2017
1 parent 94567d0 commit 17af8eb
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,4 +5,5 @@ scala/project/project/
scala/project/target/
scala/target/
scala/.ensime_cache/*
scala/bench/target/*
haskell/.stack-work/*
54 changes: 54 additions & 0 deletions scala/bench/src/main/scala/svc/Bench.scala
@@ -0,0 +1,54 @@
package svc

import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations._

// --- //

@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.NANOSECONDS)
class Bench {
/* A single call to `get`, which fetches the current "stateful" value */
@Benchmark
def oneGetCats: (Int, Int) = Kitties.oneGet

@Benchmark
def oneGetScalaz: (Int, Int) = Zed.oneGet

/* Binding speed */
@Benchmark
def bindCats: (Int, Unit) = Kitties.bind.run(1).value

@Benchmark
def flatMapCats: (Int, Unit) = Kitties.flatmap.run(1).value

@Benchmark
def bindScalaz: (Int, Unit) = Zed.bind.run(1)

@Benchmark
def flatMapScalaz: (Int, Unit) = Zed.flatmap.run(1)

/* Count down by assigning each `n` to the State */
@Benchmark
def countdownCats: (Int, Int) = Kitties.countdown.run(10000).value

@Benchmark
def countdownScalaz: (Int, Int) = Zed.trampolineCountdown.run(10000).run

@Benchmark
def countdownCatsStateTEitherT: Either[String, (Int, Unit)] =
Kitties.countdownT.run(10000).value.value

/* Silly summing using Applicative functors */
@Benchmark
def cartesianSumCats: Option[Int] = Kitties.dumbSum(List.range(0, 1000))

@Benchmark
def applicativeSumCats: Option[Int] = Kitties.dumbSum2(List.range(0, 1000))

@Benchmark
def cartesianSumScalaz: Option[Int] = Zed.dumbSum(List.range(0, 1000))

@Benchmark
def applicativeSumScalaz: Option[Int] = Zed.dumbSum2(List.range(0, 1000))
}
29 changes: 20 additions & 9 deletions scala/build.sbt
Expand Up @@ -2,15 +2,26 @@ name := """scalaz-vs-cats"""

version := "1.0"

scalaVersion := "2.12.3"
/* Settings common to each sub project */
val common = Seq(
scalaVersion := "2.11.11",

scalacOptions ++= Seq(
"-language:higherKinds",
"-Ypartial-unification"
)
scalacOptions ++= Seq(
"-language:higherKinds",
"-Ypartial-unification"
),

libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "1.0.0-MF",
"org.scalaz" %% "scalaz-core" % "7.3.0-M15",
"com.azavea" %% "scaliper" % "0.5.0-SNAPSHOT" % "test"
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "1.0.0-MF",
"org.scalaz" %% "scalaz-core" % "7.3.0-M15"
)
)

/* The library itself */
lazy val lib = project.in(file(".")).settings(common)

/* Benchmarking suite.
* Benchmarks can be executed by first switching to the `bench` project and then by running:
* jmh:run -t 1 -f 1 -wi 10 -i 10 .*Bench.*
*/
lazy val bench = project.in(file("bench")).settings(common).dependsOn(lib).enablePlugins(JmhPlugin)
1 change: 1 addition & 0 deletions scala/project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.27")
66 changes: 0 additions & 66 deletions scala/src/test/scala/svc/SVC.scala

This file was deleted.

0 comments on commit 17af8eb

Please sign in to comment.