Closed
Description
Here are instructions to run a comparative benchmark of the performance of the 2.12.2 and 2.12.3-SNAPSHOT compilers over your project sources. We're interested in finding out real-world numbers to complement our automatically run benchmarks.
The instructions below assume sbt
as your build tool. Users of other build tools can also benchmark their project, providing they first create an "args file" containing the command line to the compiler.
Create an sbt
plugin to export the compiler command line
// ~/.sbt/0.13/plugins/ArgsFile.scala
package io.github.retronym
import sbt._
import Keys._
object SbtArgsFilePlugin extends AutoPlugin {
override def trigger = allRequirements
override def requires = sbt.plugins.JvmPlugin
val argsFileContents = taskKey[String]("Contents of file suitable for `scalac @args.txt`")
val argsFile = taskKey[Unit]("Write compiler command line into an args file suitable for `scalac @target/compile.args`")
override lazy val projectSettings = List(Compile, Test).flatMap(c => inConfig(c)(Seq(
argsFileContents := {
val sourcesValue = sources.value
val depdependencyClasspathValue = dependencyClasspath.value
val cp = if (depdependencyClasspathValue.isEmpty) Nil else ("-classpath" :: depdependencyClasspathValue.map(_.data.toString).mkString(":") :: Nil)
val result = (scalacOptions.value.toList ::: List("-d", classDirectory.value) ::: cp ::: sourcesValue.distinct.toList).mkString("\n")
if (sourcesValue.isEmpty) "" else result
},
argsFile := {
val f = target.value / (c.name + ".args")
val contents = argsFileContents.value
val log = streams.value.log
if (!contents.isEmpty) {
IO.write(f, contents)
log.info("Wrote compiler comand line to: " + f.getAbsolutePath)
}
}
)))
}
Export compiler command line
We'll use the akka-actor
subproject of Akka to demonstrate.
% cd /code
% git clone https://github.com/akka/akka.git; cd akka
% sbt ++2.12.2 akka-actor/argsFile
...
[info] Wrote compiler comand line to: /code/akka/akka-actor/target/compile.args
[success] Total time: 0 s, completed 06/06/2017 9:23:35 AM
Clone the compiler-benchmark
project
% cd /code
% git clone https://github.com/scala/compiler-benchmark.git; cd compiler-benchmark
Configure a SBT resolver to access nightly builds
// ~/.sbt/0.13/resolver.sbt
resolvers ++= (
if (scalaVersion.value.contains("-bin"))
List("scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/")
else Nil
)
Quiesce your machine
- Close all other applications, check
top
to see that the machine is idle. - (for best results) disable CPU frequency scaling with http://www.rugarciap.com/turbo-boost-switcher-for-os-x/ (I use the free version)
Find latest nightly build
% curl https://scala-ci.typesafe.com/job/scala-2.12.x-integrate-bootstrap/lastSuccessfulBuild/artifact/jenkins.properties/*view*/
version=2.12.3-bin-bd6294d
sbtDistVersionOverride=-Dproject.version=2.12.3-bin-bd6294d
Use the first version number in the next step.
Execute the benchmark
% for i in 2.12.2 2.12.3-bin-37663b0-SNAPSHOT; do \
sbt "set scalaVersion in compilation := \"$i\"" 'hot -p source=@/code/akka/akka-actor/target/compile.args' || break; \
done
...
[info] # Run complete. Total time: 00:04:05
[info]
[info] Benchmark (corpusVersion) (extraArgs) (source) Mode Cnt Score Error Units
[info] HotScalacBenchmark.compile latest @/code/akka/akka-actor.args sample 24 5089.438 ± 265.585 ms/op
[info] HotScalacBenchmark.compile:compile·p0.00 latest @/code/akka/akka-actor.args sample 4815.061 ms/op
[info] HotScalacBenchmark.compile:compile·p0.50 latest @/code/akka/akka-actor.args sample 4919.919 ms/op
[info] HotScalacBenchmark.compile:compile·p0.90 latest @/code/akka/akka-actor.args sample 5511.315 ms/op
[info] HotScalacBenchmark.compile:compile·p0.95 latest @/code/akka/akka-actor.args sample 6201.278 ms/op
[info] HotScalacBenchmark.compile:compile·p0.99 latest @/code/akka/akka-actor.args sample 6358.565 ms/op
[info] HotScalacBenchmark.compile:compile·p0.999 latest @/code/akka/akka-actor.args sample 6358.565 ms/op
[info] HotScalacBenchmark.compile:compile·p0.9999 latest @/code/akka/akka-actor.args sample 6358.565 ms/op
[info] HotScalacBenchmark.compile:compile·p1.00 latest @/code/akka/akka-actor.args sample 6358.565 ms/op
[success] Total time: 247 s, completed 05/06/2017 6:39:07 PM
[info] # Run complete. Total time: 00:04:14
[info]
[info] Benchmark (corpusVersion) (extraArgs) (source) Mode Cnt Score Error Units
[info] HotScalacBenchmark.compile latest @/code/akka/akka-actor.args sample 30 4174.870 ± 170.827 ms/op
[info] HotScalacBenchmark.compile:compile·p0.00 latest @/code/akka/akka-actor.args sample 4034.920 ms/op
[info] HotScalacBenchmark.compile:compile·p0.50 latest @/code/akka/akka-actor.args sample 4099.932 ms/op
[info] HotScalacBenchmark.compile:compile·p0.90 latest @/code/akka/akka-actor.args sample 4363.754 ms/op
[info] HotScalacBenchmark.compile:compile·p0.95 latest @/code/akka/akka-actor.args sample 5027.293 ms/op
[info] HotScalacBenchmark.compile:compile·p0.99 latest @/code/akka/akka-actor.args sample 5276.434 ms/op
[info] HotScalacBenchmark.compile:compile·p0.999 latest @/code/akka/akka-actor.args sample 5276.434 ms/op
[info] HotScalacBenchmark.compile:compile·p0.9999 latest @/code/akka/akka-actor.args sample 5276.434 ms/op
[info] HotScalacBenchmark.compile:compile·p1.00 latest @/code/akka/akka-actor.args sample 5276.434 ms/op
[success] Total time: 277 s, completed 05/06/2017 6:43:50 PM
Let us know your results
In the comments below.
While you are at it
- Please run the tests of your project with the nightly build to flush out bugs
- Use
jardiff
to check for unexpected changes to the bytecode generated for your project.