Skip to content

Commit 2c56bac

Browse files
committed
refactor a bit and add a main method for easier benchmarking
1 parent 05e659a commit 2c56bac

3 files changed

Lines changed: 48 additions & 28 deletions

File tree

compiler/src/main/java/com/github/mustachejava/codes/DefaultCode.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,7 @@ public Object get(String name, Object[] scopes) {
7979
return scopes[scopes.length - 1];
8080
}
8181
if (wrapper == null) {
82-
wrapper = oh.find(name, scopes);
83-
if (wrapper == null) {
84-
notfound = true;
85-
if (debug) {
86-
// Ugly but generally not interesting
87-
if (!(this instanceof PartialCode)) {
88-
StringBuilder sb = new StringBuilder("Failed to find: ");
89-
sb.append(name).append(" in");
90-
for (Object scope : scopes) {
91-
if (scope != null) {
92-
sb.append(" ").append(scope.getClass().getSimpleName());
93-
}
94-
}
95-
logger.warning(sb.toString());
96-
}
97-
}
98-
return null;
99-
}
82+
if (getWrapper(name, scopes)) return null;
10083
}
10184
try {
10285
return oh.coerce(wrapper.call(scopes));
@@ -106,6 +89,28 @@ public Object get(String name, Object[] scopes) {
10689
}
10790
}
10891

92+
private boolean getWrapper(String name, Object[] scopes) {
93+
wrapper = oh.find(name, scopes);
94+
if (wrapper == null) {
95+
notfound = true;
96+
if (debug) {
97+
// Ugly but generally not interesting
98+
if (!(this instanceof PartialCode)) {
99+
StringBuilder sb = new StringBuilder("Failed to find: ");
100+
sb.append(name).append(" in");
101+
for (Object scope : scopes) {
102+
if (scope != null) {
103+
sb.append(" ").append(scope.getClass().getSimpleName());
104+
}
105+
}
106+
logger.warning(sb.toString());
107+
}
108+
}
109+
return true;
110+
}
111+
return false;
112+
}
113+
109114
@Override
110115
public Writer execute(Writer writer, Object scope) {
111116
return execute(writer, new Object[] { scope });

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.github.mustachejavabenchmarks;
22

3+
import com.github.mustachejava.*;
4+
import com.google.common.io.CharStreams;
5+
import junit.framework.TestCase;
6+
37
import java.io.File;
48
import java.io.IOException;
59
import java.io.InputStreamReader;
610
import java.io.StringWriter;
711
import java.util.concurrent.Executors;
812

9-
import com.github.mustachejava.*;
10-
import com.google.common.io.CharStreams;
11-
12-
import junit.framework.TestCase;
13-
1413
/**
1514
* Compare compilation with interpreter.
1615
* <p/>
@@ -102,4 +101,13 @@ private StringWriter complextest(Mustache m, Object complexObject) throws Mustac
102101
return sw;
103102
}
104103

104+
public static void main(String[] args) throws Exception {
105+
BenchmarkTest benchmarkTest = new BenchmarkTest();
106+
benchmarkTest.setUp();
107+
benchmarkTest.testComplex();
108+
benchmarkTest.testParallelComplex();
109+
benchmarkTest.testParallelComplexNoExecutor();
110+
System.exit(0);
111+
}
112+
105113
}

indy/src/test/java/com/github/mustachejava/BenchmarkTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.github.mustachejava;
22

3+
import com.github.mustachejava.indy.IndyObjectHandler;
4+
import com.google.common.io.CharStreams;
5+
import junit.framework.TestCase;
6+
37
import java.io.File;
48
import java.io.IOException;
59
import java.io.InputStreamReader;
610
import java.io.StringWriter;
711
import java.util.concurrent.Executors;
812

9-
import com.google.common.io.CharStreams;
10-
11-
import com.github.mustachejava.indy.IndyObjectHandler;
12-
import junit.framework.TestCase;
13-
1413
/**
1514
* Compare compilation with interpreter.
1615
* <p/>
@@ -108,4 +107,12 @@ private StringWriter complextest(Mustache m, Object complexObject) throws Mustac
108107
return sw;
109108
}
110109

110+
public static void main(String[] args) throws Exception {
111+
BenchmarkTest benchmarkTest = new BenchmarkTest();
112+
benchmarkTest.setUp();
113+
benchmarkTest.testComplex();
114+
benchmarkTest.testParallelComplex();
115+
benchmarkTest.testParallelComplexNoExecutor();
116+
System.exit(0);
117+
}
111118
}

0 commit comments

Comments
 (0)