Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add JTwig; update everything to the latest version #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ JMH benchmark for popular Java template engines:
* [Thymeleaf](http://www.thymeleaf.org/)
* [Trimou](http://trimou.org/)
* [Velocity](http://velocity.apache.org/)
* [JTwig](http://jtwig.org/)

Running the benchmark
======================
Expand Down
39 changes: 27 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jmh.version>1.11.2</jmh.version>

<jmh.version>1.21</jmh.version>
<uberjar.name>benchmarks</uberjar.name>

<pebble.version>2.2.0</pebble.version>
<mustache.version>0.9.1</mustache.version>
<freemarker.version>2.3.23</freemarker.version>
<pebble.version>3.0.5</pebble.version>
<mustache.version>0.9.5</mustache.version>
<freemarker.version>2.3.28</freemarker.version>
<velocity.version>1.7</velocity.version>
<thymeleaf.version>2.1.4.RELEASE</thymeleaf.version>
<thymeleaf.version>3.0.10.RELEASE</thymeleaf.version>
<trimou.version>2.5.0.Final</trimou.version>
<hbs.version>4.1.0</hbs.version>
<rocker.version>1.1.0</rocker.version>
<jtwig.version>5.87.0.RELEASE</jtwig.version>

<junit.version>4.12</junit.version>
<trimou.version>1.8.2.Final</trimou.version>
<hbs.version>4.0.1</hbs.version>
<rocker.version>0.10.3</rocker.version>
</properties>

<licenses>
Expand All @@ -47,8 +50,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -71,7 +74,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -121,7 +124,7 @@

<!-- template engines -->
<dependency>
<groupId>com.mitchellbosecke</groupId>
<groupId>io.pebbletemplates</groupId>
<artifactId>pebble</artifactId>
<version>${pebble.version}</version>
</dependency>
Expand Down Expand Up @@ -161,6 +164,18 @@
<version>${rocker.version}</version>
</dependency>

<dependency>
<groupId>org.jtwig</groupId>
<artifactId>jtwig-core</artifactId>
<version>${jtwig.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.25</version>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
17 changes: 9 additions & 8 deletions results.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"Benchmark","Mode","Threads","Samples","Score","Score Error (99.9%)","Unit"
"com.mitchellbosecke.benchmark.Freemarker.benchmark","thrpt",1,50,15370.751504,496.200994,"ops/s"
"com.mitchellbosecke.benchmark.Handlebars.benchmark","thrpt",1,50,17779.570147,552.411776,"ops/s"
"com.mitchellbosecke.benchmark.Mustache.benchmark","thrpt",1,50,22164.070102,598.799830,"ops/s"
"com.mitchellbosecke.benchmark.Pebble.benchmark","thrpt",1,50,32530.043940,849.278116,"ops/s"
"com.mitchellbosecke.benchmark.Rocker.benchmark","thrpt",1,50,39739.408090,1152.244741,"ops/s"
"com.mitchellbosecke.benchmark.Thymeleaf.benchmark","thrpt",1,50,1084.191177,33.698132,"ops/s"
"com.mitchellbosecke.benchmark.Trimou.benchmark","thrpt",1,50,22787.431476,622.350790,"ops/s"
"com.mitchellbosecke.benchmark.Velocity.benchmark","thrpt",1,50,20835.819309,526.312411,"ops/s"
"com.mitchellbosecke.benchmark.Freemarker.benchmark","thrpt",1,50,21005.588634,76.531782,"ops/s"
"com.mitchellbosecke.benchmark.Handlebars.benchmark","thrpt",1,50,20524.566711,139.586152,"ops/s"
"com.mitchellbosecke.benchmark.JTwig.benchmark","thrpt",1,50,4102.884994,48.670670,"ops/s"
"com.mitchellbosecke.benchmark.Mustache.benchmark","thrpt",1,50,23762.734119,161.242965,"ops/s"
"com.mitchellbosecke.benchmark.Pebble.benchmark","thrpt",1,50,36038.987261,109.007888,"ops/s"
"com.mitchellbosecke.benchmark.Rocker.benchmark","thrpt",1,50,42106.221964,544.817884,"ops/s"
"com.mitchellbosecke.benchmark.Thymeleaf.benchmark","thrpt",1,50,6491.056248,42.856405,"ops/s"
"com.mitchellbosecke.benchmark.Trimou.benchmark","thrpt",1,50,26884.557477,145.348522,"ops/s"
"com.mitchellbosecke.benchmark.Velocity.benchmark","thrpt",1,50,22961.235663,83.661972,"ops/s"
Binary file modified results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

import com.mitchellbosecke.benchmark.model.Stock;

@Fork(5)
@Warmup(iterations = 5)
@Measurement(iterations = 10)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Benchmark)
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/mitchellbosecke/benchmark/JTwig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mitchellbosecke.benchmark;

import org.jtwig.JtwigModel;
import org.jtwig.JtwigTemplate;
import org.jtwig.environment.EnvironmentConfiguration;
import org.jtwig.environment.EnvironmentConfigurationBuilder;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Setup;

import java.io.IOException;

public class JTwig extends BaseBenchmark {

JtwigTemplate template;
JtwigModel model;

@Setup
public void setup() throws IOException {
//disable any escaping
EnvironmentConfiguration build = EnvironmentConfigurationBuilder
.configuration()
.escape().withInitialEngine("none")
.withDefaultEngine("none")
.and().build();

template = JtwigTemplate.classpathTemplate("templates/stocks.twig.html", build);
model = JtwigModel.newModel(getContext());
}

@Benchmark
public String benchmark() throws IOException {
return template.render(model);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/templates/stocks.thymeleaf.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>Stock Prices</h1>
<tbody>
<!--/* Note that itemStat.odd works with index (starting with 0) whereas itemStat.count is starting with 1 */-->
<tr th:each="item: ${items}"
th:class="${itemStat.odd}? 'even' : 'odd'">
th:class="${itemStat.odd}? 'odd' : 'even'">
<td th:utext="${itemStat.count}"></td>
<td><a th:href="${'/stocks/' + item.symbol}"
th:utext="${item.symbol}"></a></td>
Expand Down
82 changes: 82 additions & 0 deletions src/main/resources/templates/stocks.twig.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<head>
<title>Stock Prices</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="shortcut icon" href="/images/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/css/style.css" media="all" />
<script type="text/javascript" src="/js/util.js"></script>
<style type="text/css">
/*<![CDATA[*/
body {
color: #333333;
line-height: 150%;
}

thead {
font-weight: bold;
background-color: #CCCCCC;
}

.odd {
background-color: #FFCCCC;
}

.even {
background-color: #CCCCFF;
}

.minus {
color: #FF0000;
}

/*]]>*/
</style>

</head>

<body>

<h1>Stock Prices</h1>

<table>
<thead>
<tr>
<th>#</th>
<th>symbol</th>
<th>name</th>
<th>price</th>
<th>change</th>
<th>ratio</th>
</tr>
</thead>
<tbody>
{% for item in items -%}
{% set klass = (loop.index % 2 == 0) ? "even" : "odd" %}
<tr class="{{ klass }}">
<td>{{ loop.index }}</td>
<td>
<a href="/stocks/{{ item.symbol }}">{{ item.symbol }}</a>
</td>
<td>
<a href="{{ item.url }}">{{ item.name }}</a>
</td>
<td>
<strong>{{ item.price }}</strong>
</td>
{% if (item.change < 0.0) %}
<td class="minus">{{ item.change }}</td>
<td class="minus">{{ item.ratio }}</td>
{% else %}
<td>{{ item.change }}</td>
<td>{{ item.ratio }}</td>
{% endif %}
</tr>
{% endfor -%}
</tbody>
</table>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public void testHbsOutput() throws IOException {
assertOutput(hbs.benchmark());
}

@Test
public void testJtwigOutput() throws Exception {
JTwig jTwig = new JTwig();
jTwig.setup();
assertOutput(jTwig.benchmark());
}

private void assertOutput(final String output) throws IOException {
assertEquals(readExpectedOutputResource(), output.replaceAll("\\s", ""));
}
Expand Down