From b39309efe46a16d91c5e19bc49c33b93c7689b65 Mon Sep 17 00:00:00 2001 From: Dmitri Melnikov Date: Thu, 24 Jan 2019 12:19:56 +0200 Subject: [PATCH 1/3] Add cross-compilation support for Scala-2.13.0-M5 When running benchmarks compiled with Scala 2.13 s.c.i.LazyList will be used instead of the deprecated s.c.i.Stream. --- build.sbt | 18 ++++++++++++++---- project/build.properties | 2 +- project/plugins.sbt | 2 +- src/main/scala-2.13/benchmarks/package.scala | 12 ++++++++++++ src/main/scala/benchmarks/StreamBench.scala | 1 - 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/main/scala-2.13/benchmarks/package.scala diff --git a/build.sbt b/build.sbt index e7fcc28..2297cd9 100644 --- a/build.sbt +++ b/build.sbt @@ -2,21 +2,31 @@ name := """scala-benchmarks""" version := "1.0.0" -scalaVersion := "2.12.6" +scalaVersion := "2.12.8" + +crossScalaVersions := Seq(scalaVersion.value, "2.13.0-M5") scalacOptions := Seq( "-opt:l:inline", "-opt-inline-from:**", "-deprecation", - "-Ypartial-unification", "-Ywarn-value-discard", - "-Ywarn-unused-import", + "-Ywarn-unused:imports", "-Ywarn-dead-code", "-Ywarn-numeric-widen" ) +Compile / unmanagedSourceDirectories ++= { + val mainSourceDir = baseDirectory.value / "src" / "main" / "scala" + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, 13)) => + Seq(file(mainSourceDir.getPath + "-2.13")) + case _ => Nil + } +} + libraryDependencies ++= Seq( - "org.scalaz" %% "scalaz-core" % "7.2.24" + "org.scalaz" %% "scalaz-core" % "7.2.27" ) /* To run benchmarks: diff --git a/project/build.properties b/project/build.properties index 64cf32f..c0bab04 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.1.4 +sbt.version=1.2.8 diff --git a/project/plugins.sbt b/project/plugins.sbt index be94ef1..a12e17f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.3") +addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.4") diff --git a/src/main/scala-2.13/benchmarks/package.scala b/src/main/scala-2.13/benchmarks/package.scala new file mode 100644 index 0000000..09b9861 --- /dev/null +++ b/src/main/scala-2.13/benchmarks/package.scala @@ -0,0 +1,12 @@ +package object benchmarks { + // Override references to `Stream` within `package benchmarks` to point to + // `s.c.i.LazyList` instead of `s.c.i.Stream` which was deprecated in Scala + // 2.13. + // + // Note that if for some reason this file is not included during compilation + // (for example, if sbt fails to include the Scala 2.13-specific source + // directory), then the benchmarks will still compile fine, albeit with + // warnings that `Stream` is deprecated. + type Stream[+A] = scala.collection.immutable.LazyList[A] + val Stream = scala.collection.immutable.LazyList +} diff --git a/src/main/scala/benchmarks/StreamBench.scala b/src/main/scala/benchmarks/StreamBench.scala index d83cf3f..f065267 100644 --- a/src/main/scala/benchmarks/StreamBench.scala +++ b/src/main/scala/benchmarks/StreamBench.scala @@ -39,7 +39,6 @@ class StreamBench { str1 = Stream.range(1, 10000) str2 = Stream.range(10000, 1, -1) estr1 = EphemeralStream.range(1, 10000) - estr2 = EphemeralStream.fromStream(str2) } @Benchmark From 8d0878fb40d4b38c0c1793e5c6693704c7bf3422 Mon Sep 17 00:00:00 2001 From: Dmitri Melnikov Date: Thu, 24 Jan 2019 18:55:23 +0200 Subject: [PATCH 2/3] Add running instructions to the README --- README.org | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.org b/README.org index 52c35c1..132ec1b 100644 --- a/README.org +++ b/README.org @@ -4,6 +4,34 @@ An independent set of benchmarks for testing common Scala idioms. +** Running + +To run all benchmarks for the default Scala version (2.12): +``` +# runs benchmarks according to the rules: +# -t 1 <-- one thread +# -f 1 <-- one forked JVM +# -wi 5 <-- five warmup runs before the actual measuring begins +# -i 5 <-- five actual benchmarking iterations +# .*Bench.* <-- only files matching `Bench` - which is all of them - are included in the run +$ sbt "jmh:run -t 1 -f 1 -wi 5 -i 5 .*Bench.*" +``` + +To run all benchmarks for an alternative Scala version: +``` +$ sbt "++2.13.0-M5 jmh:run -t 1 -f 1 -wi 5 -i 5 .*Bench.*" +``` + +Running all benchmarks can take a long time (i.e. hours). To specify a single `StreamBench` benchmark: +``` +$ sbt "jmh:run -t 1 -f 1 -wi 5 -i 5 .*StreamBench.*" +``` + +And to do the same for all supported Scala versions: +``` +$ sbt "+ jmh:run -t 1 -f 1 -wi 5 -i 5 .*StreamBench.*" +``` + ** Results *** Functional Programming From 96f3bc6b538b8d4be43065d9a71437df94ce3693 Mon Sep 17 00:00:00 2001 From: Dmitri Melnikov Date: Thu, 24 Jan 2019 18:59:33 +0200 Subject: [PATCH 3/3] Forgot this wasn't Markdown --- README.org | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/README.org b/README.org index 132ec1b..c24f471 100644 --- a/README.org +++ b/README.org @@ -7,30 +7,30 @@ An independent set of benchmarks for testing common Scala idioms. ** Running To run all benchmarks for the default Scala version (2.12): -``` -# runs benchmarks according to the rules: -# -t 1 <-- one thread -# -f 1 <-- one forked JVM -# -wi 5 <-- five warmup runs before the actual measuring begins -# -i 5 <-- five actual benchmarking iterations -# .*Bench.* <-- only files matching `Bench` - which is all of them - are included in the run -$ sbt "jmh:run -t 1 -f 1 -wi 5 -i 5 .*Bench.*" -``` +#+BEGIN_SRC shell + # runs benchmarks according to the rules: + # -t 1 <-- one thread + # -f 1 <-- one forked JVM + # -wi 5 <-- five warmup runs before the actual measuring begins + # -i 5 <-- five actual benchmarking iterations + # .*Bench.* <-- only files matching `Bench` - which is all of them - are included in the run + sbt "jmh:run -t 1 -f 1 -wi 5 -i 5 .*Bench.*" +#+END_SRC To run all benchmarks for an alternative Scala version: -``` -$ sbt "++2.13.0-M5 jmh:run -t 1 -f 1 -wi 5 -i 5 .*Bench.*" -``` +#+BEGIN_SRC shell + sbt "++2.13.0-M5 jmh:run -t 1 -f 1 -wi 5 -i 5 .*Bench.*" +#+END_SRC Running all benchmarks can take a long time (i.e. hours). To specify a single `StreamBench` benchmark: -``` -$ sbt "jmh:run -t 1 -f 1 -wi 5 -i 5 .*StreamBench.*" -``` +#+BEGIN_SRC shell + sbt "jmh:run -t 1 -f 1 -wi 5 -i 5 .*StreamBench.*" +#+END_SRC And to do the same for all supported Scala versions: -``` -$ sbt "+ jmh:run -t 1 -f 1 -wi 5 -i 5 .*StreamBench.*" -``` +#+BEGIN_SRC shell + sbt "+ jmh:run -t 1 -f 1 -wi 5 -i 5 .*StreamBench.*" +#+END_SRC ** Results