Unmatched Performance • Early Metrics
Flamewing Benchmarks
Benchmarking Flamewing
Tested with 100,000 iterations on AMD Ryzen 7800X3D
Flamewing is still in early development and the following benchmarks should be taken with a grain of salt and may not reflect the final version of the code. Changes may occur in the future, both positive and negative from a speed perspective. Furthermore, current benchmarks were done rudimentarily and not using proper benchmarking techniques like using JMH.
As a starter, the template for Rocker and Thymeleaf from this repository
was used, with an additional template for Flamewing which rendered the same result. However, due
to Flamewing being in early stages of development and because it needs a Spring Context to compile
the template, a simple @SpringBootTest was used. For Rocker, the template was
compiled before execution.
Using 100_000 iterations, the template was called and rendered. Execution time in ms
was monitored using System.currentTimeMillis(). I know this is NOT the best
approach, but wanted to have a general idea of the performance. Proper benchmarking will be
done in the future.
Below is a table with the results of the benchmarks on my machine (using a Ryzen 7800x3D) as well as source code of the test class that was used:
| Template Engine | Execution Time (100k calls) | Relative Speed | Status |
|---|---|---|---|
| Flamewing | 786ms | 1.0x (Fastest) | Winner |
| Rocker | 818ms | 1.04x slower | Runner-up |
| Thymeleaf | 19,251ms | 24.5x slower | Baseline |
Pages rendered in 1 second
Benchmark throughput comparison
Thymeleaf
5,194 pages
Rocker
157,009 pages
Flamewing
167,785 pages
Benchmark Test Code
Here is the exact Spring Boot test class used to execute the benchmark:
import org.example.model.Stock;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.context.IContext;
import tech.petrepopescu.flamewing.controllers.FragmentController;
import tech.petrepopescu.flamewing.parser.ElementFactory;
import tech.petrepopescu.flamewing.parser.FlamewingParser;
import tech.petrepopescu.flamewing.parser.compiler.Compiler;
import tech.petrepopescu.flamewing.parser.compiler.DynamicClassLoader;
import tech.petrepopescu.flamewing.parser.route.RouteGenerator;
import tech.petrepopescu.flamewing.special.FlamewingSpecialElementsUtil;
import tech.petrepopescu.flamewing.spring.FlamewingErrorHandler;
import tech.petrepopescu.flamewing.spring.FlamewingMessageConverter;
import tech.petrepopescu.flamewing.spring.SecurityConfig;
import tech.petrepopescu.flamewing.spring.config.FlamewingConfiguration;
import tech.petrepopescu.flamewing.spring.config.ViewsConfiguration;
import tech.petrepopescu.flamewing.views.View;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@SpringBootTest(classes = {SecurityConfig.class, FlamewingMessageConverter.class, RouteGenerator.class, Compiler.class, ElementFactory.class,
DynamicClassLoader.class, FlamewingConfiguration.class, FlamewingSpecialElementsUtil.class, FragmentController.class,
FlamewingErrorHandler.class})
@ImportAutoConfiguration(ThymeleafAutoConfiguration.class)
class FullBenchmark {
@Autowired
private Compiler compiler;
@Autowired
private RouteGenerator routeGenerator;
@Autowired
private FlamewingSpecialElementsUtil flamewingSpecialElementsUtil;
@Autowired
private TemplateEngine engine;
@Test
void benchmark() throws Exception {
List<Stock> items = Stock.dummyItems();
prepareFlamewing();
IContext context = new Context(Locale.getDefault(), getThymeleafContext(items));
System.out.println("Running benchmark...");
long rocker = runBenchmark(() -> stocks.template(items).render().toString());
long flamewing = runBenchmark(() -> View.of("Flamewing", items).getContent(flamewingSpecialElementsUtil));
long thymeleaf = runBenchmark(() -> {
Writer writer = new StringWriter();
engine.process("stocks.thymeleaf.html", context, writer);
writer.toString();
});
System.out.println("Flamewing Benchmark: " + flamewing + "ms");
System.out.println("Thymeleaf Benchmark: " + thymeleaf + "ms");
System.out.println("Rocker Benchmark: " + rocker + "ms");
}
private long runBenchmark(Runnable runnable) {
long start = System.currentTimeMillis();
for (int count = 0; count < 100_000; count++) {
runnable.run();
}
long end = System.currentTimeMillis();
return end - start;
}
private void prepareFlamewing() {
FlamewingConfiguration flamewingConfiguration = new FlamewingConfiguration();
flamewingConfiguration.setViews(new ViewsConfiguration());
flamewingConfiguration.getViews().setPath("src/test/resources/views");
FlamewingParser parser = new FlamewingParser(new ElementFactory(null), routeGenerator, compiler, flamewingConfiguration);
parser.parse();
}
protected Map<String, Object> getThymeleafContext(List<Stock> items) {
Map<String, Object> context = new HashMap<>();
context.put("items", items);
return context;
}
}