forked from winterbe/java8-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNashorn10.java
More file actions
27 lines (20 loc) · 814 Bytes
/
Nashorn10.java
File metadata and controls
27 lines (20 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.winterbe.java8.samples.nashorn;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.concurrent.TimeUnit;
/**
* @author Benjamin Winterberg
*/
public class Nashorn10 {
public static void main(String[] args) throws ScriptException, NoSuchMethodException {
NashornScriptEngine engine = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn");
engine.eval("load('res/nashorn10.js')");
long t0 = System.nanoTime();
for (int i = 0; i < 100000; i++) {
engine.invokeFunction("testPerf");
}
long took = System.nanoTime() - t0;
System.out.format("Elapsed time: %d ms", TimeUnit.NANOSECONDS.toMillis(took));
}
}