Skip to content

Commit 3f9518d

Browse files
committed
WIP - redo benchmarks
1 parent 5e05d3f commit 3f9518d

File tree

5 files changed

+237
-140
lines changed

5 files changed

+237
-140
lines changed

bench/src/main/scala/Benchmarks.scala

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package dotty.tools.benchmarks
2+
3+
import dotty.tools.dotc._
4+
import core.Contexts.Context
5+
6+
import org.openjdk.jmh.results.RunResult
7+
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+
16+
17+
import java.io.{File, FileOutputStream, BufferedWriter, FileWriter}
18+
import scala.collection.JavaConversions._
19+
import scala.io.Source
20+
21+
object Bench {
22+
val COMPILE_OPTS_FILE = "compile.txt"
23+
24+
def main(args: Array[String]): Unit = {
25+
storeCompileOptions(args)
26+
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
29+
30+
/*
31+
val results = runner.run() // actually run the benchmarks
32+
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+
*/
40+
}
41+
42+
def storeCompileOptions(args: Array[String]): Unit = {
43+
val file = new File(COMPILE_OPTS_FILE)
44+
val bw = new BufferedWriter(new FileWriter(file))
45+
bw.write(args.mkString("\n"))
46+
bw.close()
47+
}
48+
49+
def readCompileOptions: Seq[String] =
50+
Source.fromFile(COMPILE_OPTS_FILE).getLines.toSeq
51+
}
52+
53+
@State(Scope.Benchmark)
54+
class CompilerOptions {
55+
var opts: Array[String] = null
56+
57+
@Setup
58+
def prepare: Unit = {
59+
opts = Bench.readCompileOptions.to[Array]
60+
}
61+
}
62+
63+
class Worker extends Driver {
64+
override def newCompiler(implicit ctx: Context): Compiler = new Compiler
65+
66+
@Benchmark
67+
def compile(state: CompilerOptions): Unit = {
68+
println("options: " + state.opts.mkString(", "))
69+
super.main(state.opts)
70+
}
71+
}

bench/templates/launch.mustache

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#!/bin/sh
2+
#/*--------------------------------------------------------------------------
3+
# * Copyright 2012 Taro L. Saito
4+
# *
5+
# * Licensed under the Apache License, Version 2.0 (the "License");
6+
# * you may not use this file except in compliance with the License.
7+
# * You may obtain a copy of the License at
8+
# *
9+
# * http://www.apache.org/licenses/LICENSE-2.0
10+
# *
11+
# * Unless required by applicable law or agreed to in writing, software
12+
# * distributed under the License is distributed on an "AS IS" BASIS,
13+
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# * See the License for the specific language governing permissions and
15+
# * limitations under the License.
16+
# *--------------------------------------------------------------------------*/
17+
18+
if [ -z "$PROG_HOME" ] ; then
19+
## resolve links - $0 may be a link to PROG_HOME
20+
PRG="$0"
21+
22+
# need this for relative symlinks
23+
while [ -h "$PRG" ] ; do
24+
ls=`ls -ld "$PRG"`
25+
link=`expr "$ls" : '.*-> \(.*\)$'`
26+
if expr "$link" : '/.*' > /dev/null; then
27+
PRG="$link"
28+
else
29+
PRG="`dirname "$PRG"`/$link"
30+
fi
31+
done
32+
33+
saveddir=`pwd`
34+
35+
PROG_HOME=`dirname "$PRG"`/..
36+
37+
# make it fully qualified
38+
PROG_HOME=`cd "$PROG_HOME" && pwd`
39+
40+
cd "$saveddir"
41+
fi
42+
43+
44+
cygwin=false
45+
mingw=false
46+
darwin=false
47+
case "`uname`" in
48+
CYGWIN*) cygwin=true
49+
;;
50+
MINGW*) mingw=true
51+
;;
52+
Darwin*) darwin=true
53+
if [ -z "$JAVA_VERSION" ] ; then
54+
JAVA_VERSION="CurrentJDK"
55+
else
56+
echo "Using Java version: $JAVA_VERSION" 1>&2
57+
fi
58+
if [ -z "$JAVA_HOME" ] ; then
59+
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
60+
fi
61+
JAVA_OPTS="$JAVA_OPTS -Xdock:name=\"${PROG_NAME}\" -Xdock:icon=\"$PROG_HOME/{{{MAC_ICON_FILE}}}\" -Dapple.laf.useScreenMenuBar=true"
62+
JAVACMD="`which java`"
63+
;;
64+
esac
65+
66+
# Resolve JAVA_HOME from javac command path
67+
if [ -z "$JAVA_HOME" ]; then
68+
javaExecutable="`which javac`"
69+
if [ -n "$javaExecutable" -a -f "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
70+
# readlink(1) is not available as standard on Solaris 10.
71+
readLink=`which readlink`
72+
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
73+
javaExecutable="`readlink -f \"$javaExecutable\"`"
74+
javaHome="`dirname \"$javaExecutable\"`"
75+
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
76+
JAVA_HOME="$javaHome"
77+
export JAVA_HOME
78+
fi
79+
fi
80+
fi
81+
82+
83+
if [ -z "$JAVACMD" ] ; then
84+
if [ -n "$JAVA_HOME" ] ; then
85+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
86+
# IBM's JDK on AIX uses strange locations for the executables
87+
JAVACMD="$JAVA_HOME/jre/sh/java"
88+
else
89+
JAVACMD="$JAVA_HOME/bin/java"
90+
fi
91+
else
92+
JAVACMD="`which java`"
93+
fi
94+
fi
95+
96+
if [ ! -x "$JAVACMD" ] ; then
97+
echo "Error: JAVA_HOME is not defined correctly."
98+
echo " We cannot execute $JAVACMD"
99+
exit 1
100+
fi
101+
102+
if [ -z "$JAVA_HOME" ] ; then
103+
echo "Warning: JAVA_HOME environment variable is not set."
104+
fi
105+
106+
CLASSPATH_SUFFIX=""
107+
# Path separator used in EXTRA_CLASSPATH
108+
PSEP=":"
109+
110+
# For Cygwin, switch paths to Windows-mixed format before running java
111+
if $cygwin; then
112+
[ -n "$PROG_HOME" ] &&
113+
PROG_HOME=`cygpath -am "$PROG_HOME"`
114+
[ -n "$JAVA_HOME" ] &&
115+
JAVA_HOME=`cygpath -am "$JAVA_HOME"`
116+
CLASSPATH_SUFFIX=";"
117+
PSEP=";"
118+
fi
119+
120+
# For Migwn, ensure paths are in UNIX format before anything is touched
121+
if $mingw ; then
122+
[ -n "$PROG_HOME" ] &&
123+
PROG_HOME="`(cd "$PROG_HOME"; pwd -W | sed 's|/|\\\\|g')`"
124+
[ -n "$JAVA_HOME" ] &&
125+
JAVA_HOME="`(cd "$JAVA_HOME"; pwd -W | sed 's|/|\\\\|g')`"
126+
CLASSPATH_SUFFIX=";"
127+
PSEP=";"
128+
fi
129+
130+
131+
PROG_NAME={{{PROG_NAME}}}
132+
PROG_VERSION={{{PROG_VERSION}}}
133+
PROG_REVISION={{{PROG_REVISION}}}
134+
135+
eval exec "\"$JAVACMD\"" \
136+
{{{JVM_OPTS}}} \
137+
${JAVA_OPTS} \
138+
{{^EXPANDED_CLASSPATH}}
139+
-Xbootclasspath/a:"'{{{EXTRA_CLASSPATH}}}${PROG_HOME}/lib/*${CLASSPATH_SUFFIX}'" \
140+
{{/EXPANDED_CLASSPATH}}
141+
{{#EXPANDED_CLASSPATH}}
142+
-Xbootclasspath/a:"'{{{EXTRA_CLASSPATH}}}{{{EXPANDED_CLASSPATH}}}${CLASSPATH_SUFFIX}'" \
143+
{{/EXPANDED_CLASSPATH}}
144+
-Dprog.home="'${PROG_HOME}'" \
145+
-Dprog.version="${PROG_VERSION}" \
146+
-Dprog.revision="${PROG_REVISION}" \
147+
{{{MAIN_CLASS}}} \"\$@\"
148+
exit $?

bench/test/dotty/tools/benchmarks/Benchmarks.scala

Lines changed: 0 additions & 108 deletions
This file was deleted.

project/Build.scala

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import dotty.tools.sbtplugin.DottyIDEPlugin.autoImport._
2020
import org.scalajs.sbtplugin.ScalaJSPlugin
2121
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
2222

23+
import pl.project13.scala.sbt.JmhPlugin
24+
import JmhPlugin.JmhKeys.Jmh
25+
2326
/* In sbt 0.13 the Build trait would expose all vals to the shell, where you
2427
* can use them in "set a := b" like expressions. This re-exposes them.
2528
*/
@@ -822,42 +825,22 @@ object Build {
822825
)))
823826

824827
lazy val `dotty-bench` = project.in(file("bench")).
825-
dependsOn(`dotty-compiler` % "compile->test").
828+
dependsOn(`dotty-compiler`).
826829
settings(commonNonBootstrappedSettings).
827830
settings(
828-
baseDirectory in (Test,run) := (baseDirectory in `dotty-compiler`).value,
829-
830-
libraryDependencies += "com.storm-enroute" %% "scalameter" % "0.6" % Test,
831+
mainClass in (Jmh, run) := Some("dotty.tools.benchmarks.Bench"), // custom main for jmh:run
831832

832833
fork in Test := true,
833-
parallelExecution in Test := false,
834-
835-
// http://grokbase.com/t/gg/simple-build-tool/135ke5y90p/sbt-setting-jvm-boot-paramaters-for-scala
836-
javaOptions ++= {
837-
val attList = (dependencyClasspath in Runtime).value
838-
val bin = (packageBin in Compile).value
839-
840-
// put the Scala {library, reflect, compiler} in the classpath
841-
val path = for {
842-
file <- attList.map(_.data)
843-
path = file.getAbsolutePath
844-
prefix = if (path.endsWith(".jar")) "p" else "a"
845-
} yield "-Xbootclasspath/" + prefix + ":" + path
846-
// dotty itself needs to be in the bootclasspath
847-
val fullpath = ("-Xbootclasspath/a:" + bin) :: path.toList
848-
// System.err.println("BOOTPATH: " + fullpath)
849-
850-
val ci_build = // propagate if this is a ci build
851-
if (sys.props.isDefinedAt(JENKINS_BUILD))
852-
List(s"-D$JENKINS_BUILD=${sys.props(JENKINS_BUILD)}")
853-
else if (sys.props.isDefinedAt(DRONE_MEM))
854-
List("-Xmx" + sys.props(DRONE_MEM))
855-
else
856-
List()
857-
val res = agentOptions ::: ci_build ::: fullpath
858-
println("Running with javaOptions: " + res)
859-
res
860-
}
834+
parallelExecution in Test := false
835+
).
836+
enablePlugins(JmhPlugin).
837+
settings(packSettings).
838+
settings(
839+
publishArtifact := false,
840+
packMain := Map("bench" -> "dotty.tools.benchmarks.Bench"),
841+
packGenerateWindowsBatFile := false,
842+
packExpandedClasspath := true,
843+
packBashTemplate := baseDirectory.value + "/templates/launch.mustache"
861844
)
862845

863846
// Depend on dotty-library so that sbt projects using dotty automatically

0 commit comments

Comments
 (0)