Skip to content

Commit 4c0c411

Browse files
committed
Make benchmarks work again and simplify benchmarking procedure
1 parent 907dfcf commit 4c0c411

File tree

7 files changed

+37
-25
lines changed

7 files changed

+37
-25
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ target
55
/.settings
66
/.target
77
/bin
8+
benchmark/JmhBench.scala

benchmark/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ Because the benchmarking is **very computationally expensive** it should be done
66

77
## Code generation step
88

9-
1. Run `sbt console`
10-
11-
2. If the `JmhBench.scala` file already exists, delete it.
9+
1. Make sure the parent project has been built by running `sbt package` in it.
1210

13-
3. Enter `bench.codegen.Generate.jmhBench()` to generate the `JmhBench.scala` file.
11+
2. `cd` to the benchmark project and run `sbt generateJmh`
1412

1513
## Benchmarking step
1614

benchmark/build.sbt

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
enablePlugins(JmhPlugin)
22

3+
val generateJmh = TaskKey[Unit]("generateJmh", "Generates JMH benchmark sources.")
4+
35
lazy val root = (project in file(".")).settings(
46
name := "java8-compat-bench",
5-
scalaVersion := "2.11.7",
6-
crossScalaVersions := List("2.11.7" /* TODO, "2.12.0-M3"*/),
7+
scalaVersion := "2.11.8",
8+
crossScalaVersions := List("2.11.8" /* TODO, "2.12.0-M4"*/),
79
organization := "org.scala-lang.modules",
810
version := "0.6.0-SNAPSHOT",
9-
unmanagedJars in Compile ++= Seq(baseDirectory.value / "../target/scala-2.11/scala-java8-compat_2.11-0.6.0-SNAPSHOT.jar")
11+
unmanagedJars in Compile ++= Seq(baseDirectory.value / "../target/scala-2.11/scala-java8-compat_2.11-0.8.0-SNAPSHOT.jar"),
12+
// This would be nicer but sbt-jmh doesn't like it:
13+
//unmanagedClasspath in Compile += Attributed.blank(baseDirectory.value / "../target/scala-2.11/classes"),
14+
generateJmh := (runMain in Compile).toTask(" bench.codegen.GenJmhBench").value
1015
)

benchmark/project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.5")
1+
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.6")

benchmark/src/main/scala/bench/CodeGen.scala

+8
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,11 @@ object Generator {
232232
}
233233
}
234234
}
235+
236+
object GenJmhBench {
237+
def main(args: Array[String]): Unit = {
238+
val f = new java.io.File("JmhBench.scala")
239+
f.delete()
240+
Generator.jmhBench(f)
241+
}
242+
}

benchmark/src/main/scala/bench/CollectionSource.scala

+16-16
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,30 @@ package object generate {
2525
}
2626

2727
object Pstep {
28-
def i[CC](cc: CC)(implicit steppize: CC => MakesIntStepper): IntStepper =
28+
def i[CC](cc: CC)(implicit steppize: CC => MakesStepper[IntStepper with EfficientSubstep]): IntStepper =
2929
steppize(cc).stepper
30-
def s[CC](cc: CC)(implicit steppize: CC => MakesAnyStepper[String]): AnyStepper[String] =
30+
def s[CC](cc: CC)(implicit steppize: CC => MakesStepper[AnyStepper[String] with EfficientSubstep]): AnyStepper[String] =
3131
steppize(cc).stepper
3232
}
3333

3434
object Sstep {
35-
def i[CC](cc: CC)(implicit steppize: CC => MakesIntSeqStepper): IntStepper =
35+
def i[CC](cc: CC)(implicit steppize: CC => MakesStepper[IntStepper]): IntStepper =
3636
steppize(cc).stepper
37-
def s[CC](cc: CC)(implicit steppize: CC => MakesAnySeqStepper[String]): AnyStepper[String] =
37+
def s[CC](cc: CC)(implicit steppize: CC => MakesStepper[AnyStepper[String]]): AnyStepper[String] =
3838
steppize(cc).stepper
3939
}
4040

4141
object PsStream {
42-
def i[CC](cc: CC)(implicit steppize: CC => MakesIntStepper): IntStream =
42+
def i[CC](cc: CC)(implicit steppize: CC => MakesStepper[IntStepper with EfficientSubstep]): IntStream =
4343
steppize(cc).stepper.parStream
44-
def s[CC](cc: CC)(implicit steppize: CC => MakesAnyStepper[String]): Stream[String] =
44+
def s[CC](cc: CC)(implicit steppize: CC => MakesStepper[AnyStepper[String] with EfficientSubstep]): Stream[String] =
4545
steppize(cc).stepper.parStream
4646
}
4747

4848
object SsStream {
49-
def i[CC](cc: CC)(implicit steppize: CC => MakesIntSeqStepper): IntStream =
49+
def i[CC](cc: CC)(implicit steppize: CC => MakesStepper[IntStepper]): IntStream =
5050
steppize(cc).stepper.seqStream
51-
def s[CC](cc: CC)(implicit steppize: CC => MakesAnySeqStepper[String]): Stream[String] =
51+
def s[CC](cc: CC)(implicit steppize: CC => MakesStepper[AnyStepper[String]]): Stream[String] =
5252
steppize(cc).stepper.seqStream
5353
}
5454

@@ -78,14 +78,14 @@ package object generate {
7878
// Iterator
7979
def iI(j: Int)(implicit x: CC[Int] => Iterator[Int]) = x(cI(j))
8080
// Steppers (second letter--s = sequential, p = parallel)
81-
def tsI(j: Int)(implicit x: CC[Int] => MakesIntSeqStepper) = Sstep i cI(j)
82-
def tpI(j: Int)(implicit x: CC[Int] => MakesIntStepper) = Pstep i cI(j)
81+
def tsI(j: Int)(implicit x: CC[Int] => MakesStepper[IntStepper]) = Sstep i cI(j)
82+
def tpI(j: Int)(implicit x: CC[Int] => MakesStepper[IntStepper with EfficientSubstep]) = Pstep i cI(j)
8383
// Streams
8484
def ssI(j: Int)(implicit x: CC[Int] => MakesSequentialStream[java.lang.Integer, IntStream]) = Sstream i cI(j)
8585
def spI(j: Int)(implicit x: CC[Int] => MakesParallelStream[java.lang.Integer, IntStream]) = Pstream i cI(j)
8686
// Streams via steppers
87-
def zsI(j: Int)(implicit x: CC[Int] => MakesIntSeqStepper) = SsStream i cI(j)
88-
def zpI(j: Int)(implicit x: CC[Int] => MakesIntStepper) = PsStream i cI(j)
87+
def zsI(j: Int)(implicit x: CC[Int] => MakesStepper[IntStepper]) = SsStream i cI(j)
88+
def zpI(j: Int)(implicit x: CC[Int] => MakesStepper[IntStepper with EfficientSubstep]) = PsStream i cI(j)
8989
}
9090

9191
trait StringThingsOf[CC[_]] extends GenThingsOf[CC] {
@@ -95,14 +95,14 @@ package object generate {
9595
// Iterator
9696
def iS(j: Int)(implicit x: CC[String] => Iterator[String]) = x(cS(j))
9797
// Steppers (second letter--s = sequential, p = parallel)
98-
def tsS(j: Int)(implicit x: CC[String] => MakesAnySeqStepper[String]) = Sstep s cS(j)
99-
def tpS(j: Int)(implicit x: CC[String] => MakesAnyStepper[String]) = Pstep s cS(j)
98+
def tsS(j: Int)(implicit x: CC[String] => MakesStepper[AnyStepper[String]]) = Sstep s cS(j)
99+
def tpS(j: Int)(implicit x: CC[String] => MakesStepper[AnyStepper[String] with EfficientSubstep]) = Pstep s cS(j)
100100
// Streams
101101
def ssS(j: Int)(implicit x: CC[String] => MakesSequentialStream[String, Stream[String]]) = Sstream s cS(j)
102102
def spS(j: Int)(implicit x: CC[String] => MakesParallelStream[String, Stream[String]]) = Pstream s cS(j)
103103
// Streams via steppers
104-
def zsS(j: Int)(implicit x: CC[String] => MakesAnySeqStepper[String]) = SsStream s cS(j)
105-
def zpS(j: Int)(implicit x: CC[String] => MakesAnyStepper[String]) = PsStream s cS(j)
104+
def zsS(j: Int)(implicit x: CC[String] => MakesStepper[AnyStepper[String]]) = SsStream s cS(j)
105+
def zpS(j: Int)(implicit x: CC[String] => MakesStepper[AnyStepper[String] with EfficientSubstep]) = PsStream s cS(j)
106106
}
107107

108108
trait ThingsOf[CC[_]] extends IntThingsOf[CC] with StringThingsOf[CC] {}

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ lazy val root = (project in file(".")).
109109
"""|import scala.concurrent._
110110
|import ExecutionContext.Implicits.global
111111
|import java.util.concurrent.{CompletionStage,CompletableFuture}
112-
|import scala.compat.java8.FutureConverter._
112+
|import scala.compat.java8.FutureConverters._
113113
|""".stripMargin
114114
)

0 commit comments

Comments
 (0)