Skip to content

Commit 762db5e

Browse files
committed
jhm works
The generated script `bench` accept all compiler options 1. `sbt bench/pack` to generate compiler artifacts & scripts 2. `bench/target/pack/bin/bench examples/hello.scala`
1 parent 3f9518d commit 762db5e

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

bench/src/main/scala/Benchmarks.scala

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ import core.Contexts.Context
55

66
import org.openjdk.jmh.results.RunResult
77
import org.openjdk.jmh.runner.Runner
8-
import org.openjdk.jmh.runner.options.CommandLineOptions
9-
import org.openjdk.jmh.annotations.Benchmark
10-
import org.openjdk.jmh.annotations.State
11-
import org.openjdk.jmh.annotations.Scope
12-
13-
import org.openjdk.jmh.annotations.Setup
14-
import org.openjdk.jmh.annotations.TearDown
15-
8+
import org.openjdk.jmh.runner.options.OptionsBuilder
9+
import org.openjdk.jmh.annotations._
10+
import org.openjdk.jmh.results.format._
11+
import java.util.concurrent.TimeUnit
1612

1713
import java.io.{File, FileOutputStream, BufferedWriter, FileWriter}
1814
import scala.collection.JavaConversions._
@@ -24,21 +20,27 @@ object Bench {
2420
def main(args: Array[String]): Unit = {
2521
storeCompileOptions(args)
2622

27-
val opts = new CommandLineOptions() // parse command line arguments, and then bend them to your will! ;-)
28-
val runner = new Runner(opts) // full access to all JMH features, you can also provide a custom output Format here
23+
val libs = System.getenv("BOOTSTRAP_APPEND")
2924

30-
/*
31-
val results = runner.run() // actually run the benchmarks
25+
val opts = new OptionsBuilder()
26+
.jvmArgsPrepend(s"-Xbootclasspath/a:$libs")
27+
.mode(Mode.AverageTime)
28+
.timeUnit(TimeUnit.MICROSECONDS)
29+
.forks(5)
30+
.warmupIterations(5)
31+
.measurementIterations(10)
32+
.resultFormat(ResultFormatType.CSV)
33+
.result("result.csv")
34+
.build
3235

33-
val f = new FileOutputStream(new File("custom.out"))
34-
results.foreach { result: RunResult ⇒
35-
// usually you'd use these results to report into some external aggregation tool for example
36-
f.write(s"custom reporting result: ${result.getAggregatedResult.getPrimaryResult}".getBytes("UTF-8"))
37-
}
38-
f.close()
39-
*/
36+
val runner = new Runner(opts) // full access to all JMH features, you can also provide a custom output Format here
37+
runner.run() // actually run the benchmarks
38+
39+
removeCompileOptions
4040
}
4141

42+
def removeCompileOptions: Unit = new File(COMPILE_OPTS_FILE).delete()
43+
4244
def storeCompileOptions(args: Array[String]): Unit = {
4345
val file = new File(COMPILE_OPTS_FILE)
4446
val bw = new BufferedWriter(new FileWriter(file))
@@ -65,7 +67,7 @@ class Worker extends Driver {
6567

6668
@Benchmark
6769
def compile(state: CompilerOptions): Unit = {
68-
println("options: " + state.opts.mkString(", "))
69-
super.main(state.opts)
70+
val res = process(state.opts)
71+
if (res.hasErrors) throw new Exception("compilation failed")
7072
}
7173
}

bench/templates/launch.mustache

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ case "`uname`" in
5858
if [ -z "$JAVA_HOME" ] ; then
5959
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
6060
fi
61-
JAVA_OPTS="$JAVA_OPTS -Xdock:name=\"${PROG_NAME}\" -Xdock:icon=\"$PROG_HOME/{{{MAC_ICON_FILE}}}\" -Dapple.laf.useScreenMenuBar=true"
6261
JAVACMD="`which java`"
6362
;;
6463
esac
@@ -132,17 +131,17 @@ PROG_NAME={{{PROG_NAME}}}
132131
PROG_VERSION={{{PROG_VERSION}}}
133132
PROG_REVISION={{{PROG_REVISION}}}
134133

134+
# add default libraries for compilation
135+
export BOOTSTRAP_APPEND="{{{EXPANDED_CLASSPATH}}}${CLASSPATH_SUFFIX}"
136+
135137
eval exec "\"$JAVACMD\"" \
136138
{{{JVM_OPTS}}} \
137139
${JAVA_OPTS} \
138140
{{^EXPANDED_CLASSPATH}}
139-
-Xbootclasspath/a:"'{{{EXTRA_CLASSPATH}}}${PROG_HOME}/lib/*${CLASSPATH_SUFFIX}'" \
141+
-cp "'{{{EXTRA_CLASSPATH}}}${PROG_HOME}/lib/*${CLASSPATH_SUFFIX}'" \
140142
{{/EXPANDED_CLASSPATH}}
141143
{{#EXPANDED_CLASSPATH}}
142-
-Xbootclasspath/a:"'{{{EXTRA_CLASSPATH}}}{{{EXPANDED_CLASSPATH}}}${CLASSPATH_SUFFIX}'" \
144+
-cp "'{{{EXTRA_CLASSPATH}}}{{{EXPANDED_CLASSPATH}}}${CLASSPATH_SUFFIX}'" \
143145
{{/EXPANDED_CLASSPATH}}
144-
-Dprog.home="'${PROG_HOME}'" \
145-
-Dprog.version="${PROG_VERSION}" \
146-
-Dprog.revision="${PROG_REVISION}" \
147146
{{{MAIN_CLASS}}} \"\$@\"
148147
exit $?

project/Build.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,10 +828,7 @@ object Build {
828828
dependsOn(`dotty-compiler`).
829829
settings(commonNonBootstrappedSettings).
830830
settings(
831-
mainClass in (Jmh, run) := Some("dotty.tools.benchmarks.Bench"), // custom main for jmh:run
832-
833-
fork in Test := true,
834-
parallelExecution in Test := false
831+
mainClass in (Jmh, run) := Some("dotty.tools.benchmarks.Bench") // custom main for jmh:run
835832
).
836833
enablePlugins(JmhPlugin).
837834
settings(packSettings).

0 commit comments

Comments
 (0)