diff --git a/.gitignore b/.gitignore index 86fb982..41ed2bf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ target /.settings /.target /bin +benchmark/JmhBench.scala \ No newline at end of file diff --git a/benchmark/README.md b/benchmark/README.md index eb68ef9..c7d3491 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -6,11 +6,9 @@ Because the benchmarking is **very computationally expensive** it should be done ## Code generation step -1. Run `sbt console` - -2. If the `JmhBench.scala` file already exists, delete it. +1. Make sure the parent project has been built by running `sbt package` in it. -3. Enter `bench.codegen.Generate.jmhBench()` to generate the `JmhBench.scala` file. +2. `cd` to the benchmark project and run `sbt generateJmh` ## Benchmarking step diff --git a/benchmark/build.sbt b/benchmark/build.sbt index 5365275..5a7420f 100644 --- a/benchmark/build.sbt +++ b/benchmark/build.sbt @@ -1,10 +1,15 @@ enablePlugins(JmhPlugin) +val generateJmh = TaskKey[Unit]("generateJmh", "Generates JMH benchmark sources.") + lazy val root = (project in file(".")).settings( name := "java8-compat-bench", - scalaVersion := "2.11.7", - crossScalaVersions := List("2.11.7" /* TODO, "2.12.0-M3"*/), + scalaVersion := "2.11.8", + crossScalaVersions := List("2.11.8" /* TODO, "2.12.0-M4"*/), organization := "org.scala-lang.modules", version := "0.6.0-SNAPSHOT", - unmanagedJars in Compile ++= Seq(baseDirectory.value / "../target/scala-2.11/scala-java8-compat_2.11-0.6.0-SNAPSHOT.jar") + unmanagedJars in Compile ++= Seq(baseDirectory.value / "../target/scala-2.11/scala-java8-compat_2.11-0.8.0-SNAPSHOT.jar"), + // This would be nicer but sbt-jmh doesn't like it: + //unmanagedClasspath in Compile += Attributed.blank(baseDirectory.value / "../target/scala-2.11/classes"), + generateJmh := (runMain in Compile).toTask(" bench.codegen.GenJmhBench").value ) diff --git a/benchmark/project/plugins.sbt b/benchmark/project/plugins.sbt index c5220d0..f5319fb 100644 --- a/benchmark/project/plugins.sbt +++ b/benchmark/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.5") +addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.6") diff --git a/benchmark/src/main/scala/bench/CodeGen.scala b/benchmark/src/main/scala/bench/CodeGen.scala index 4e206ce..09a1af3 100644 --- a/benchmark/src/main/scala/bench/CodeGen.scala +++ b/benchmark/src/main/scala/bench/CodeGen.scala @@ -232,3 +232,11 @@ object Generator { } } } + +object GenJmhBench { + def main(args: Array[String]): Unit = { + val f = new java.io.File("JmhBench.scala") + f.delete() + Generator.jmhBench(f) + } +} diff --git a/benchmark/src/main/scala/bench/CollectionSource.scala b/benchmark/src/main/scala/bench/CollectionSource.scala index 689aa42..5f40a33 100644 --- a/benchmark/src/main/scala/bench/CollectionSource.scala +++ b/benchmark/src/main/scala/bench/CollectionSource.scala @@ -25,30 +25,30 @@ package object generate { } object Pstep { - def i[CC](cc: CC)(implicit steppize: CC => MakesIntStepper): IntStepper = + def i[CC](cc: CC)(implicit steppize: CC => MakesStepper[IntStepper with EfficientSubstep]): IntStepper = steppize(cc).stepper - def s[CC](cc: CC)(implicit steppize: CC => MakesAnyStepper[String]): AnyStepper[String] = + def s[CC](cc: CC)(implicit steppize: CC => MakesStepper[AnyStepper[String] with EfficientSubstep]): AnyStepper[String] = steppize(cc).stepper } object Sstep { - def i[CC](cc: CC)(implicit steppize: CC => MakesIntSeqStepper): IntStepper = + def i[CC](cc: CC)(implicit steppize: CC => MakesStepper[IntStepper]): IntStepper = steppize(cc).stepper - def s[CC](cc: CC)(implicit steppize: CC => MakesAnySeqStepper[String]): AnyStepper[String] = + def s[CC](cc: CC)(implicit steppize: CC => MakesStepper[AnyStepper[String]]): AnyStepper[String] = steppize(cc).stepper } object PsStream { - def i[CC](cc: CC)(implicit steppize: CC => MakesIntStepper): IntStream = + def i[CC](cc: CC)(implicit steppize: CC => MakesStepper[IntStepper with EfficientSubstep]): IntStream = steppize(cc).stepper.parStream - def s[CC](cc: CC)(implicit steppize: CC => MakesAnyStepper[String]): Stream[String] = + def s[CC](cc: CC)(implicit steppize: CC => MakesStepper[AnyStepper[String] with EfficientSubstep]): Stream[String] = steppize(cc).stepper.parStream } object SsStream { - def i[CC](cc: CC)(implicit steppize: CC => MakesIntSeqStepper): IntStream = + def i[CC](cc: CC)(implicit steppize: CC => MakesStepper[IntStepper]): IntStream = steppize(cc).stepper.seqStream - def s[CC](cc: CC)(implicit steppize: CC => MakesAnySeqStepper[String]): Stream[String] = + def s[CC](cc: CC)(implicit steppize: CC => MakesStepper[AnyStepper[String]]): Stream[String] = steppize(cc).stepper.seqStream } @@ -78,14 +78,14 @@ package object generate { // Iterator def iI(j: Int)(implicit x: CC[Int] => Iterator[Int]) = x(cI(j)) // Steppers (second letter--s = sequential, p = parallel) - def tsI(j: Int)(implicit x: CC[Int] => MakesIntSeqStepper) = Sstep i cI(j) - def tpI(j: Int)(implicit x: CC[Int] => MakesIntStepper) = Pstep i cI(j) + def tsI(j: Int)(implicit x: CC[Int] => MakesStepper[IntStepper]) = Sstep i cI(j) + def tpI(j: Int)(implicit x: CC[Int] => MakesStepper[IntStepper with EfficientSubstep]) = Pstep i cI(j) // Streams def ssI(j: Int)(implicit x: CC[Int] => MakesSequentialStream[java.lang.Integer, IntStream]) = Sstream i cI(j) def spI(j: Int)(implicit x: CC[Int] => MakesParallelStream[java.lang.Integer, IntStream]) = Pstream i cI(j) // Streams via steppers - def zsI(j: Int)(implicit x: CC[Int] => MakesIntSeqStepper) = SsStream i cI(j) - def zpI(j: Int)(implicit x: CC[Int] => MakesIntStepper) = PsStream i cI(j) + def zsI(j: Int)(implicit x: CC[Int] => MakesStepper[IntStepper]) = SsStream i cI(j) + def zpI(j: Int)(implicit x: CC[Int] => MakesStepper[IntStepper with EfficientSubstep]) = PsStream i cI(j) } trait StringThingsOf[CC[_]] extends GenThingsOf[CC] { @@ -95,14 +95,14 @@ package object generate { // Iterator def iS(j: Int)(implicit x: CC[String] => Iterator[String]) = x(cS(j)) // Steppers (second letter--s = sequential, p = parallel) - def tsS(j: Int)(implicit x: CC[String] => MakesAnySeqStepper[String]) = Sstep s cS(j) - def tpS(j: Int)(implicit x: CC[String] => MakesAnyStepper[String]) = Pstep s cS(j) + def tsS(j: Int)(implicit x: CC[String] => MakesStepper[AnyStepper[String]]) = Sstep s cS(j) + def tpS(j: Int)(implicit x: CC[String] => MakesStepper[AnyStepper[String] with EfficientSubstep]) = Pstep s cS(j) // Streams def ssS(j: Int)(implicit x: CC[String] => MakesSequentialStream[String, Stream[String]]) = Sstream s cS(j) def spS(j: Int)(implicit x: CC[String] => MakesParallelStream[String, Stream[String]]) = Pstream s cS(j) // Streams via steppers - def zsS(j: Int)(implicit x: CC[String] => MakesAnySeqStepper[String]) = SsStream s cS(j) - def zpS(j: Int)(implicit x: CC[String] => MakesAnyStepper[String]) = PsStream s cS(j) + def zsS(j: Int)(implicit x: CC[String] => MakesStepper[AnyStepper[String]]) = SsStream s cS(j) + def zpS(j: Int)(implicit x: CC[String] => MakesStepper[AnyStepper[String] with EfficientSubstep]) = PsStream s cS(j) } trait ThingsOf[CC[_]] extends IntThingsOf[CC] with StringThingsOf[CC] {} diff --git a/build.sbt b/build.sbt index 9c0d927..c2da864 100644 --- a/build.sbt +++ b/build.sbt @@ -109,6 +109,6 @@ lazy val root = (project in file(".")). """|import scala.concurrent._ |import ExecutionContext.Implicits.global |import java.util.concurrent.{CompletionStage,CompletableFuture} - |import scala.compat.java8.FutureConverter._ + |import scala.compat.java8.FutureConverters._ |""".stripMargin )