Skip to content

Commit

Permalink
Move HelloWorld and Scalafmt benchmarks to their own suite
Browse files Browse the repository at this point in the history
  • Loading branch information
loicottet committed Jun 15, 2021
1 parent cbc5a97 commit 34e8516
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package bench.misc;
package bench.console;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

@State(Scope.Benchmark)
public class HelloWorld {
@Benchmark
public static void helloWorld() {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package bench.misc;
package bench.console;

import org.openjdk.jmh.annotations.*;

@State(Scope.Benchmark)
public class Scalafmt {

private static final String file =
Expand Down Expand Up @@ -130,8 +127,7 @@ public class Scalafmt {
" }\n" +
"}\n";

@Benchmark
public static String bench() {
return org.scalafmt.Scalafmt.format(file, org.scalafmt.Scalafmt.format$default$2(), org.scalafmt.Scalafmt.format$default$3()).get();
public static void main(String[] args) {
org.scalafmt.Scalafmt.format(file, org.scalafmt.Scalafmt.format$default$2(), org.scalafmt.Scalafmt.format$default$3()).get();
}
}
70 changes: 70 additions & 0 deletions java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2033,3 +2033,73 @@ def run(self, benchmarks, bmSuiteArgs):


mx_benchmark.add_bm_suite(AWFYBenchmarkSuite())


_consoleConfig = {
"helloworld": {
"mainClass": "bench.console.HelloWorld",
"args": []
},
"scalafmt": {
"mainClass": "bench.console.Scalafmt",
"args": []
}
}

class ConsoleBenchmarkSuite(mx_benchmark.JavaBenchmarkSuite):
"""Hello World benchmark suite implementation.
"""
def name(self):
return "console"

def group(self):
return "Graal"

def subgroup(self):
return "graal-compiler"

def benchSuiteName(self, bmSuiteArgs=None):
return self.name()

def helloWorldPath(self):
helloWorld = mx.distribution("GRAAL_BENCH_CONSOLE")
if helloWorld:
return helloWorld.path
return None

def classpathAndMainClass(self, benchmark):
main_class = _consoleConfig.get(benchmark)["mainClass"]
return ["-cp", self.helloWorldPath(), main_class]

def appArgs(self, benchmark):
return _consoleConfig.get(benchmark)["args"]

def createCommandLineArgs(self, benchmarks, bmSuiteArgs):
if benchmarks is None:
mx.abort("Suite can only run a single benchmark per VM instance.")
elif len(benchmarks) != 1:
mx.abort("Must specify exactly one benchmark to run.")
elif benchmarks[0] not in self.benchmarkList(bmSuiteArgs):
mx.abort("The specified benchmark doesn't exist. Possible values are: " + ", ".join(self.benchmarkList(bmSuiteArgs)))
vmArgs = self.runArgs(bmSuiteArgs)
runArgs = self.runArgs(bmSuiteArgs)
appArgs = self.appArgs(benchmarks[0])
return (vmArgs + self.classpathAndMainClass(benchmarks[0]) + runArgs + appArgs)

def benchmarkList(self, bmSuiteArgs):
return sorted(_consoleConfig.keys())

def successPatterns(self):
return []

def failurePatterns(self):
return [
re.compile(
r"^\[\[\[Graal compilation failure\]\]\]", # pylint: disable=line-too-long
re.MULTILINE)
]

def rules(self, output, benchmarks, bmSuiteArgs):
return []

mx_benchmark.add_bm_suite(ConsoleBenchmarkSuite())
18 changes: 17 additions & 1 deletion java-benchmarks/mx.java-benchmarks/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@
"sourceDirs" : ["src"],
"dependencies" : [
"mx:JMH_1_21",
"SCALAFMT"
],
"javaCompliance" : "8+",
"checkPackagePrefix" : "false",
Expand All @@ -349,6 +348,17 @@
"workingSets" : "Graal,Bench",
"testProject" : True,
},
"org.graalvm.bench.console" : {
"subDir" : "java",
"sourceDirs" : ["src"],
"dependencies" : [
"SCALAFMT"
],
"javaCompliance" : "8+",
"checkPackagePrefix" : "false",
"workingSets" : "Graal,Bench",
"testProject" : True,
},
},

"imports" : {
Expand All @@ -372,6 +382,12 @@
"dependencies" : ["org.graalvm.bench.shootouts"],
"testDistribution" : True,
"maven": False,
},
"GRAAL_BENCH_CONSOLE" : {
"subDir" : "java",
"dependencies" : ["org.graalvm.bench.console"],
"testDistribution" : True,
"maven": False,
}
}
}
20 changes: 20 additions & 0 deletions substratevm/mx.substratevm/mx_substratevm_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,23 @@ def substitution_path():


mx_benchmark.add_bm_suite(ScalaDaCapoNativeImageBenchmarkSuite())


class ConsoleNativeImageBenchmarkSuite(mx_java_benchmarks.ConsoleBenchmarkSuite, mx_sdk_benchmark.NativeImageBenchmarkMixin): #pylint: disable=too-many-ancestors
"""
Console applications suite for Native Image
"""

def name(self):
return 'console-native-image'

def benchSuiteName(self, bmSuiteArgs=None):
return 'console'

def createCommandLineArgs(self, benchmarks, bmSuiteArgs):
args = super(ConsoleNativeImageBenchmarkSuite, self).createCommandLineArgs(benchmarks, bmSuiteArgs)
self.benchmark_name = benchmarks[0]
return args


mx_benchmark.add_bm_suite(ConsoleNativeImageBenchmarkSuite())

0 comments on commit 34e8516

Please sign in to comment.