Skip to content

Commit 215aed9

Browse files
committed
Another perf test to compare 8u31 vs 8u40
1 parent a42a7d4 commit 215aed9

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

res/nashorn10.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var results = [];
2+
3+
var Context = function () {
4+
this.foo = 'bar';
5+
};
6+
7+
Context.prototype.testArgs = function () {
8+
if (arguments[0]) {
9+
results.push(true);
10+
}
11+
if (arguments[1]) {
12+
results.push(true);
13+
}
14+
if (arguments[2]) {
15+
results.push(true);
16+
}
17+
if (arguments[3]) {
18+
results.push(true);
19+
}
20+
};
21+
22+
var testPerf = function () {
23+
var context = new Context();
24+
context.testArgs();
25+
context.testArgs(1);
26+
context.testArgs(1, 2);
27+
context.testArgs(1, 2, 3);
28+
context.testArgs(1, 2, 3, 4);
29+
};

src/com/winterbe/java8/Nashorn10.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.winterbe.java8;
2+
3+
import jdk.nashorn.api.scripting.NashornScriptEngine;
4+
5+
import javax.script.ScriptEngineManager;
6+
import javax.script.ScriptException;
7+
import java.util.concurrent.TimeUnit;
8+
9+
/**
10+
* @author Benjamin Winterberg
11+
*/
12+
public class Nashorn10 {
13+
14+
public static void main(String[] args) throws ScriptException, NoSuchMethodException {
15+
NashornScriptEngine engine = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn");
16+
engine.eval("load('res/nashorn10.js')");
17+
18+
long t0 = System.nanoTime();
19+
20+
for (int i = 0; i < 100000; i++) {
21+
engine.invokeFunction("testPerf");
22+
}
23+
24+
long took = System.nanoTime() - t0;
25+
System.out.format("Elapsed time: %d ms", TimeUnit.NANOSECONDS.toMillis(took));
26+
}
27+
}

0 commit comments

Comments
 (0)