Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

Commit d70b151

Browse files
committed
Netbeans format.
1 parent e59f298 commit d70b151

File tree

1 file changed

+76
-79
lines changed

1 file changed

+76
-79
lines changed

src/main/java/com/mycompany/app/App.java

Lines changed: 76 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,131 +5,128 @@
55
import javax.script.ScriptEngineManager;
66
import javax.script.ScriptEngine;
77
import javax.script.Invocable;
8-
import java.io.File;
9-
import java.io.FileReader;
108
import java.io.IOException;
11-
import java.io.InputStreamReader;
129

1310
/**
1411
* Simple benchmark for Graal.js via GraalVM Polyglot Context and ScriptEngine.
1512
*/
1613
public class App {
1714

18-
public static final int WARMUP=10;
19-
public static final int ITERATIONS=10;
20-
public static final String BENCHFILE = "src/bench.js";
15+
public static final int WARMUP = 10;
16+
public static final int ITERATIONS = 10;
17+
public static final String BENCHFILE = "src/bench.js";
2118

22-
public static final String SOURCE = "" +
23-
"var N = 2000;\n" +
24-
"var EXPECTED = 17393;\n" +
25-
"\n" +
26-
"function Natural() {\n" +
27-
" x = 2;\n" +
28-
" return {\n" +
29-
" 'next' : function() { return x++; }\n" +
30-
" };\n" +
31-
"}\n" +
32-
"\n" +
33-
"function Filter(number, filter) {\n" +
34-
" var self = this;\n" +
35-
" this.number = number;\n" +
36-
" this.filter = filter;\n" +
37-
" this.accept = function(n) {\n" +
38-
" var filter = self;\n" +
39-
" for (;;) {\n" +
40-
" if (n % filter.number === 0) {\n" +
41-
" return false;\n" +
42-
" }\n" +
43-
" filter = filter.filter;\n" +
44-
" if (filter === null) {\n" +
45-
" break;\n" +
46-
" }\n" +
47-
" }\n" +
48-
" return true;\n" +
49-
" };\n" +
50-
" return this;\n" +
51-
"}\n" +
52-
"\n" +
53-
"function Primes(natural) {\n" +
54-
" var self = this;\n" +
55-
" this.natural = natural;\n" +
56-
" this.filter = null;\n" +
57-
"\n" +
58-
" this.next = function() {\n" +
59-
" for (;;) {\n" +
60-
" var n = self.natural.next();\n" +
61-
" if (self.filter === null || self.filter.accept(n)) {\n" +
62-
" self.filter = new Filter(n, self.filter);\n" +
63-
" return n;\n" +
64-
" }\n" +
65-
" }\n" +
66-
" };\n" +
67-
"}\n" +
68-
"\n" +
69-
"function primesMain() {\n" +
70-
" var primes = new Primes(Natural());\n" +
71-
" var primArray = [];\n" +
72-
" for (var i=0;i<=N;i++) { primArray.push(primes.next()); }\n" +
73-
" if (primArray[N] != EXPECTED) { throw new Error('wrong prime found: '+primArray[N]); }\n" +
74-
"}\n";
19+
public static final String SOURCE = ""
20+
+ "var N = 2000;\n"
21+
+ "var EXPECTED = 17393;\n"
22+
+ "\n"
23+
+ "function Natural() {\n"
24+
+ " x = 2;\n"
25+
+ " return {\n"
26+
+ " 'next' : function() { return x++; }\n"
27+
+ " };\n"
28+
+ "}\n"
29+
+ "\n"
30+
+ "function Filter(number, filter) {\n"
31+
+ " var self = this;\n"
32+
+ " this.number = number;\n"
33+
+ " this.filter = filter;\n"
34+
+ " this.accept = function(n) {\n"
35+
+ " var filter = self;\n"
36+
+ " for (;;) {\n"
37+
+ " if (n % filter.number === 0) {\n"
38+
+ " return false;\n"
39+
+ " }\n"
40+
+ " filter = filter.filter;\n"
41+
+ " if (filter === null) {\n"
42+
+ " break;\n"
43+
+ " }\n"
44+
+ " }\n"
45+
+ " return true;\n"
46+
+ " };\n"
47+
+ " return this;\n"
48+
+ "}\n"
49+
+ "\n"
50+
+ "function Primes(natural) {\n"
51+
+ " var self = this;\n"
52+
+ " this.natural = natural;\n"
53+
+ " this.filter = null;\n"
54+
+ "\n"
55+
+ " this.next = function() {\n"
56+
+ " for (;;) {\n"
57+
+ " var n = self.natural.next();\n"
58+
+ " if (self.filter === null || self.filter.accept(n)) {\n"
59+
+ " self.filter = new Filter(n, self.filter);\n"
60+
+ " return n;\n"
61+
+ " }\n"
62+
+ " }\n"
63+
+ " };\n"
64+
+ "}\n"
65+
+ "\n"
66+
+ "function primesMain() {\n"
67+
+ " var primes = new Primes(Natural());\n"
68+
+ " var primArray = [];\n"
69+
+ " for (var i=0;i<=N;i++) { primArray.push(primes.next()); }\n"
70+
+ " if (primArray[N] != EXPECTED) { throw new Error('wrong prime found: '+primArray[N]); }\n"
71+
+ "}\n";
7572

76-
public static void main(String[] args) throws Exception {
73+
public static void main(String[] args) throws Exception {
7774
benchGraalPolyglotContext();
7875
benchGraalScriptEngine();
7976
benchNashornScriptEngine();
8077
}
8178

82-
private static void benchGraalPolyglotContext() throws IOException {
83-
System.out.println("=== Graal.js via org.graalvm.polyglot.Context === ");
84-
try (Context context = Context.create()) {
79+
private static void benchGraalPolyglotContext() throws IOException {
80+
System.out.println("=== Graal.js via org.graalvm.polyglot.Context === ");
81+
try (Context context = Context.create()) {
8582
context.eval("js", SOURCE);
8683
Value primesMain = context.getBindings("js").getMember("primesMain");
8784
System.out.println("warming up ...");
88-
for (int i=0;i<WARMUP;i++) {
85+
for (int i = 0; i < WARMUP; i++) {
8986
primesMain.execute();
9087
}
9188
System.out.println("warmup finished, now measuring");
92-
for (int i=0;i<ITERATIONS;i++) {
89+
for (int i = 0; i < ITERATIONS; i++) {
9390
long start = System.currentTimeMillis();
9491
primesMain.execute();
95-
System.out.println("iteration: "+(System.currentTimeMillis()-start));
92+
System.out.println("iteration: " + (System.currentTimeMillis() - start));
9693
}
97-
} // context.close() is automatic
98-
}
94+
} // context.close() is automatic
95+
}
9996

100-
private static void benchNashornScriptEngine() throws IOException {
101-
System.out.println("=== Nashorn via javax.script.ScriptEngine ===");
97+
private static void benchNashornScriptEngine() throws IOException {
98+
System.out.println("=== Nashorn via javax.script.ScriptEngine ===");
10299
ScriptEngine nashornEngine = new ScriptEngineManager().getEngineByName("nashorn");
103100
if (nashornEngine == null) {
104101
System.out.println("*** Nashorn not found ***");
105102
} else {
106103
benchScriptEngineIntl(nashornEngine);
107104
}
108-
}
105+
}
109106

110-
private static void benchGraalScriptEngine() throws IOException {
111-
System.out.println("=== Graal.js via javax.script.ScriptEngine ===");
107+
private static void benchGraalScriptEngine() throws IOException {
108+
System.out.println("=== Graal.js via javax.script.ScriptEngine ===");
112109
ScriptEngine graaljsEngine = new ScriptEngineManager().getEngineByName("graal.js");
113110
if (graaljsEngine == null) {
114111
System.out.println("*** Graal.js not found ***");
115112
} else {
116113
benchScriptEngineIntl(graaljsEngine);
117114
}
118-
}
115+
}
119116

120117
private static void benchScriptEngineIntl(ScriptEngine eng) throws IOException {
121118
try {
122-
eng.eval(SOURCE);
123-
Invocable inv = (Invocable)eng;
119+
eng.eval(SOURCE);
120+
Invocable inv = (Invocable) eng;
124121
System.out.println("warming up ...");
125-
for (int i=0;i<WARMUP;i++) {
122+
for (int i = 0; i < WARMUP; i++) {
126123
inv.invokeFunction("primesMain");
127124
}
128125
System.out.println("warmup finished, now measuring");
129-
for (int i=0;i<ITERATIONS;i++) {
126+
for (int i = 0; i < ITERATIONS; i++) {
130127
long start = System.currentTimeMillis();
131128
inv.invokeFunction("primesMain");
132-
System.out.println("iteration: "+(System.currentTimeMillis()-start));
129+
System.out.println("iteration: " + (System.currentTimeMillis() - start));
133130
}
134131
} catch (Exception ex) {
135132
System.out.println(ex);

0 commit comments

Comments
 (0)