Skip to content

Commit a651178

Browse files
committed
add it to the benchmarks. not impressive.
1 parent 77be555 commit a651178

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

compiler/src/test/java/com/github/mustachejavabenchmarks/JsonInterpreterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void testMultithreaded() throws IOException, InterruptedException {
127127
}
128128
}
129129

130-
private Object getScope() throws IOException {
130+
protected Object getScope() throws IOException {
131131
MappingJsonFactory jf = new MappingJsonFactory();
132132
InputStream json = getClass().getClassLoader().getResourceAsStream("hogan.json");
133133
final Map node = (Map) toObject(jf.createJsonParser(json).readValueAsTree());

javascript/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
<version>4.12</version>
2424
<scope>test</scope>
2525
</dependency>
26+
<dependency>
27+
<groupId>org.codehaus.jackson</groupId>
28+
<artifactId>jackson-mapper-asl</artifactId>
29+
<version>1.9.3</version>
30+
<scope>test</scope>
31+
</dependency>
2632
<dependency>
2733
<groupId>com.github.spullara.mustache.java</groupId>
2834
<artifactId>compiler</artifactId>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.github.mustachejavabenchmarks;
2+
3+
import com.github.mustachejava.DefaultMustacheFactory;
4+
import com.github.mustachejava.JavascriptObjectHandler;
5+
6+
import javax.script.ScriptEngine;
7+
import javax.script.ScriptEngineManager;
8+
import javax.script.ScriptException;
9+
import java.io.ByteArrayOutputStream;
10+
import java.io.IOException;
11+
import java.io.InputStream;
12+
13+
public class JavascriptInterpreterTest extends JsonInterpreterTest {
14+
@Override
15+
protected Object getScope() throws IOException {
16+
ScriptEngineManager sem = new ScriptEngineManager();
17+
ScriptEngine se = sem.getEngineByName("nashorn");
18+
InputStream json = getClass().getClassLoader().getResourceAsStream("hogan.json");
19+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
20+
byte[] bytes = new byte[1024];
21+
int read;
22+
while ((read = json.read(bytes)) != -1) {
23+
baos.write(bytes, 0, read);
24+
}
25+
try {
26+
return se.eval("var tweet = " + new String(baos.toByteArray()) + "; " +
27+
"var tweets = []; for (var i = 0; i < 50; i++) { tweets.push(tweet); };" +
28+
"this;");
29+
} catch (ScriptException e) {
30+
throw new RuntimeException(e);
31+
}
32+
}
33+
34+
@Override
35+
protected DefaultMustacheFactory createMustacheFactory() {
36+
DefaultMustacheFactory mustacheFactory = new DefaultMustacheFactory(root);
37+
mustacheFactory.setObjectHandler(new JavascriptObjectHandler());
38+
return mustacheFactory;
39+
}
40+
}

0 commit comments

Comments
 (0)