Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include indy in benchmark runs #569

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions benchmark/README.adoc
@@ -0,0 +1,45 @@
//////////////////////////////////////////

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

//////////////////////////////////////////

= Benchmarks

In order to run the benchmarks you must have the `JAVA_HOME` environment
variable set.

The benchmarks will be run using the version of Apache Groovy that executes
the `bench.groovy` script. For example, to execute benchmarks using version
*2.4.12*:

groovy-2.4.12/bin/groovy ./benchmark/bench.groovy

To execute the benchmarks against the current source directory, first
build an installation:

./gradlew installGroovy

Then execute the benchmarks with that installation:

./target/install/bin/groovy ./benchmark/bench.groovy

To execute a single benchmark pass the name of the benchmark without the
file extension:

./target/install/bin/groovy ./benchmark/bench.groovy hello
54 changes: 36 additions & 18 deletions benchmark/bench.groovy
Expand Up @@ -70,12 +70,21 @@ def benchData = [
wordfreq : [1],*/
]

setGroovyLib()
// Find base directory for script to allow executing from other directories
benchmarkDir = new File(getClass().protectionDomain.codeSource.location.path).parent
execDir = new File(benchmarkDir, 'exec')
if (execDir.exists()) {
cleanFolder()
} else {
execDir.mkdir()
}

groovyAllJar = getGroovyAllJar()

horizontalBreak()
println "Groovy benchmarking test"
showJavaVersion()
println "Groovy lib: $GROOVY_LIB"
println "Groovy lib: $groovyAllJar"
horizontalBreak()
def executeBench= { bench, input ->
println "Benchmark $bench"
Expand All @@ -85,6 +94,12 @@ def executeBench= { bench, input ->
boolean exists = prepare(bench, ending)
if (exists) {
execBenchmark(bench, input)
if (ending == '.groovy') {
cleanFolder()
println "\t$bench$ending (indy) : "
prepare(bench, ending, true)
execBenchmark(bench, input)
}
} else {
println "skipped"
}
Expand All @@ -97,26 +112,30 @@ if (args.length==0) {
} else {
executeBench(args[0],benchData[args[0]])
}

execDir.delete()

void horizontalBreak() {
println "-" * 80
}

boolean prepare(bench, ending) {
boolean prepare(bench, ending, indy=false) {
// copy file to exec folder it it exists
def orig = new File("bench/$bench$ending")
def orig = new File(benchmarkDir, "bench/$bench$ending")
if (!orig.exists()) return false;

// compile file using groovy compiler
// in = orig, out = exec
Compiler.main("-j","-d", "exec", orig.absolutePath)
def args = ['-j', '-d', execDir.absolutePath]
if (indy) {
args << '-indy'
}
args << orig.absolutePath
Compiler.main(args as String[])
true
}

void cleanFolder(){
def dir = new File("exec/")
dir.eachFile { file -> file.delete() }
execDir.eachFile { file -> file.delete() }
}

String javaHome() {
Expand All @@ -138,9 +157,8 @@ void showJavaVersion() {

void execBenchmark(bench, input) {
input.each { param ->
def cp = "./exec/" + File.pathSeparatorChar
cp += GROOVY_LIB + File.pathSeparatorChar
cp += "../target/lib/runtime/*"
def cp = execDir.absolutePath + File.pathSeparatorChar
cp += groovyAllJar + File.pathSeparatorChar

def time1 = System.nanoTime()

Expand All @@ -167,12 +185,12 @@ void printProgress(it) {
if (n==3) print "\b-"
}

void setGroovyLib() {
def f = new File("../target/libs")
f.eachFile { entry ->
def name = entry.name
if (!name.startsWith("groovy-all")) return
if (name.contains("sources")) return
GROOVY_LIB = entry.absolutePath
String getGroovyAllJar() {
String jar = ''
new File(System.getProperty('groovy.home'), 'embeddable').eachFile { entry ->
if (entry.name.startsWith('groovy-all')) {
jar = entry.absolutePath
}
}
return jar
}