Skip to content

Commit a42a7d4

Browse files
committed
Add perf test to compare 8u31 vs 8u40
1 parent ad3faa0 commit a42a7d4

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

res/nashorn9.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var size = 100000;
2+
3+
var testPerf = function () {
4+
var result = Math.floor(Math.random() * size) + 1;
5+
for (var i = 0; i < size; i++) {
6+
result += i;
7+
}
8+
return result;
9+
};

src/com/winterbe/java8/Nashorn9.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 Nashorn9 {
13+
14+
public static void main(String[] args) throws ScriptException, NoSuchMethodException {
15+
NashornScriptEngine engine = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn");
16+
engine.eval("load('res/nashorn9.js')");
17+
18+
long t0 = System.nanoTime();
19+
20+
double result = 0;
21+
for (int i = 0; i < 1000; i++) {
22+
double num = (double) engine.invokeFunction("testPerf");
23+
result += num;
24+
}
25+
26+
System.out.println(result > 0);
27+
28+
long took = System.nanoTime() - t0;
29+
System.out.format("Elapsed time: %d ms", TimeUnit.NANOSECONDS.toMillis(took));
30+
}
31+
}

0 commit comments

Comments
 (0)