Skip to content

Commit

Permalink
jhm works
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
liufengyun committed Jul 13, 2017
1 parent 3f9518d commit 762db5e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
44 changes: 23 additions & 21 deletions bench/src/main/scala/Benchmarks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ import core.Contexts.Context

import org.openjdk.jmh.results.RunResult
import org.openjdk.jmh.runner.Runner
import org.openjdk.jmh.runner.options.CommandLineOptions
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.Scope

import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.TearDown

import org.openjdk.jmh.runner.options.OptionsBuilder
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.results.format._
import java.util.concurrent.TimeUnit

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

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

/*
val results = runner.run() // actually run the benchmarks
val opts = new OptionsBuilder()
.jvmArgsPrepend(s"-Xbootclasspath/a:$libs")
.mode(Mode.AverageTime)
.timeUnit(TimeUnit.MICROSECONDS)
.forks(5)
.warmupIterations(5)
.measurementIterations(10)
.resultFormat(ResultFormatType.CSV)
.result("result.csv")
.build

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

removeCompileOptions
}

def removeCompileOptions: Unit = new File(COMPILE_OPTS_FILE).delete()

def storeCompileOptions(args: Array[String]): Unit = {
val file = new File(COMPILE_OPTS_FILE)
val bw = new BufferedWriter(new FileWriter(file))
Expand All @@ -65,7 +67,7 @@ class Worker extends Driver {

@Benchmark
def compile(state: CompilerOptions): Unit = {
println("options: " + state.opts.mkString(", "))
super.main(state.opts)
val res = process(state.opts)
if (res.hasErrors) throw new Exception("compilation failed")
}
}
11 changes: 5 additions & 6 deletions bench/templates/launch.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ case "`uname`" in
if [ -z "$JAVA_HOME" ] ; then
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
fi
JAVA_OPTS="$JAVA_OPTS -Xdock:name=\"${PROG_NAME}\" -Xdock:icon=\"$PROG_HOME/{{{MAC_ICON_FILE}}}\" -Dapple.laf.useScreenMenuBar=true"
JAVACMD="`which java`"
;;
esac
Expand Down Expand Up @@ -132,17 +131,17 @@ PROG_NAME={{{PROG_NAME}}}
PROG_VERSION={{{PROG_VERSION}}}
PROG_REVISION={{{PROG_REVISION}}}

# add default libraries for compilation
export BOOTSTRAP_APPEND="{{{EXPANDED_CLASSPATH}}}${CLASSPATH_SUFFIX}"

eval exec "\"$JAVACMD\"" \
{{{JVM_OPTS}}} \
${JAVA_OPTS} \
{{^EXPANDED_CLASSPATH}}
-Xbootclasspath/a:"'{{{EXTRA_CLASSPATH}}}${PROG_HOME}/lib/*${CLASSPATH_SUFFIX}'" \
-cp "'{{{EXTRA_CLASSPATH}}}${PROG_HOME}/lib/*${CLASSPATH_SUFFIX}'" \
{{/EXPANDED_CLASSPATH}}
{{#EXPANDED_CLASSPATH}}
-Xbootclasspath/a:"'{{{EXTRA_CLASSPATH}}}{{{EXPANDED_CLASSPATH}}}${CLASSPATH_SUFFIX}'" \
-cp "'{{{EXTRA_CLASSPATH}}}{{{EXPANDED_CLASSPATH}}}${CLASSPATH_SUFFIX}'" \
{{/EXPANDED_CLASSPATH}}
-Dprog.home="'${PROG_HOME}'" \
-Dprog.version="${PROG_VERSION}" \
-Dprog.revision="${PROG_REVISION}" \
{{{MAIN_CLASS}}} \"\$@\"
exit $?
5 changes: 1 addition & 4 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -828,10 +828,7 @@ object Build {
dependsOn(`dotty-compiler`).
settings(commonNonBootstrappedSettings).
settings(
mainClass in (Jmh, run) := Some("dotty.tools.benchmarks.Bench"), // custom main for jmh:run

fork in Test := true,
parallelExecution in Test := false
mainClass in (Jmh, run) := Some("dotty.tools.benchmarks.Bench") // custom main for jmh:run
).
enablePlugins(JmhPlugin).
settings(packSettings).
Expand Down

0 comments on commit 762db5e

Please sign in to comment.