Skip to content

Commit b2b5e4d

Browse files
authored
Merge pull request #114 from retronym/javac-benchmark-separate
Separate javac benchmark to a subproject to sidestep JPMS issue
2 parents ce803ee + c982329 commit b2b5e4d

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

build.sbt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ lazy val compilation = addJmh(project).settings(
6767
fork in (Test, test) := true, // jmh scoped tasks run with fork := true.
6868
).settings(addJavaOptions).dependsOn(infrastructure)
6969

70+
lazy val javaCompilation = addJmh(project).settings(
71+
description := "Black box benchmark of the java compiler",
72+
crossPaths := false,
73+
mainClass in (Jmh, run) := Some("scala.bench.ScalacBenchmarkRunner"),
74+
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test,
75+
testOptions in Test += Tests.Argument(TestFrameworks.JUnit),
76+
fork in (Test, test) := true // jmh scoped tasks run with fork := true.
77+
).settings(addJavaOptions).dependsOn(infrastructure)
78+
7079
lazy val micro = addJmh(project).settings(
7180
description := "Finer grained benchmarks of compiler internals",
7281
libraryDependencies += scalaOrganization.value % "scala-compiler" % scalaVersion.value

compilation/src/main/scala/scala/tools/nsc/HotSbtBenchmark.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package scala.tools.nsc
33
import java.io._
44
import java.nio.file._
55
import java.util.concurrent.TimeUnit
6-
76
import org.openjdk.jmh.annotations.Mode
87
import org.openjdk.jmh.annotations._
98

9+
import scala.bench.IOUtils
10+
1011
@State(Scope.Benchmark)
1112
@BenchmarkMode(Array(org.openjdk.jmh.annotations.Mode.SampleTime))
1213
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@@ -166,7 +167,7 @@ class HotSbtBenchmark {
166167
@TearDown(Level.Trial) def terminate(): Unit = {
167168
processOutputReader.close()
168169
sbtProcess.destroyForcibly()
169-
BenchmarkUtils.deleteRecursive(tempDir)
170-
BenchmarkUtils.deleteRecursive(scalaHome)
170+
IOUtils.deleteRecursive(tempDir)
171+
IOUtils.deleteRecursive(scalaHome)
171172
}
172173
}

compilation/src/main/scala/scala/tools/nsc/ScalacBenchmark.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package scala.tools.nsc
33
import java.io.File
44
import java.nio.file._
55
import java.util.concurrent.TimeUnit
6-
76
import com.typesafe.config.ConfigFactory
87
import org.openjdk.jmh.annotations.Mode._
98
import org.openjdk.jmh.annotations._
109
import org.openjdk.jmh.profile.AsyncProfiler
10+
import org.openjdk.jmh.runner.Runner
1111

12+
import scala.bench.IOUtils
1213
import scala.tools.benchmark.BenchmarkDriver
1314

1415
trait BaseBenchmarkDriver {
@@ -74,7 +75,7 @@ class ScalacBenchmark extends BenchmarkDriver {
7475
else {
7576
val sourceDir = findSourceDir
7677
val sourceAssemblyDir = Paths.get(ConfigFactory.load.getString("sourceAssembly.localdir"))
77-
BenchmarkUtils.deleteRecursive(sourceAssemblyDir)
78+
IOUtils.deleteRecursive(sourceAssemblyDir)
7879
BenchmarkUtils.prepareSources(sourceDir, sourceAssemblyDir, scalaVersion)
7980
}
8081

@@ -161,3 +162,15 @@ class HotScalacBenchmark extends ScalacBenchmark {
161162
@Benchmark
162163
def compile(): Unit = compileProfiled()
163164
}
165+
166+
object BakeOff {
167+
def main(args: Array[String]): Unit = {
168+
import org.openjdk.jmh.runner.options.Options
169+
import org.openjdk.jmh.runner.options.OptionsBuilder
170+
import org.openjdk.jmh.runner.options.TimeValue
171+
import org.openjdk.jmh.runner.options.VerboseMode
172+
val baseOpts = new OptionsBuilder().include(classOf[HotScalacBenchmark].getName).warmupTime(TimeValue.milliseconds(200)).measurementTime(TimeValue.milliseconds(200)).warmupIterations(5).measurementIterations(5).forks(2).verbosity(VerboseMode.SILENT).build
173+
new OptionsBuilder().parent(baseOpts).jvmArgsPrepend("-classpath", "-")
174+
new Runner(baseOpts)
175+
}
176+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package scala.bench;
2+
3+
import java.io.IOException;
4+
import java.nio.file.FileVisitResult;
5+
import java.nio.file.Files;
6+
import java.nio.file.Path;
7+
import java.nio.file.SimpleFileVisitor;
8+
import java.nio.file.attribute.BasicFileAttributes;
9+
10+
public abstract class IOUtils {
11+
private IOUtils() {}
12+
13+
public static void deleteRecursive(Path directory) throws IOException {
14+
if (Files.exists(directory)) {
15+
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
16+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
17+
Files.delete(file);
18+
return FileVisitResult.CONTINUE;
19+
}
20+
21+
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
22+
Files.delete(dir);
23+
return FileVisitResult.CONTINUE;
24+
}
25+
});
26+
}
27+
}
28+
}

compilation/src/main/scala/scala/tools/nsc/JavacBenchmark.java renamed to javaCompilation/src/main/scala/scala/tools/nsc/JavacBenchmark.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ public int bench() {
9797
tempFile.mkdir();
9898
tempDir = tempFile;
9999
}
100-
@TearDown(Level.Trial) public void clearTemp() {
101-
BenchmarkUtils.deleteRecursive(tempDir.toPath());
100+
@TearDown(Level.Trial) public void clearTemp() throws IOException {
101+
scala.bench.IOUtils.deleteRecursive(tempDir.toPath());
102102
}
103-
104103
}

0 commit comments

Comments
 (0)