forked from winterbe/java8-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNashorn9.java
More file actions
31 lines (23 loc) · 911 Bytes
/
Nashorn9.java
File metadata and controls
31 lines (23 loc) · 911 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
28
29
30
31
package com.winterbe.java8;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.concurrent.TimeUnit;
/**
* @author Benjamin Winterberg
*/
public class Nashorn9 {
public static void main(String[] args) throws ScriptException, NoSuchMethodException {
NashornScriptEngine engine = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn");
engine.eval("load('res/nashorn9.js')");
long t0 = System.nanoTime();
double result = 0;
for (int i = 0; i < 1000; i++) {
double num = (double) engine.invokeFunction("testPerf");
result += num;
}
System.out.println(result > 0);
long took = System.nanoTime() - t0;
System.out.format("Elapsed time: %d ms", TimeUnit.NANOSECONDS.toMillis(took));
}
}