Skip to content

Instantly share code, notes, and snippets.

@jawher
Created November 12, 2012 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jawher/4058518 to your computer and use it in GitHub Desktop.
Save jawher/4058518 to your computer and use it in GitHub Desktop.
public class ThymeleafBenchmark implements Benchmark {
private Context context;
private TemplateEngine engine;
public ThymeleafBenchmark(Collection<Todo> todos) {
engine = new TemplateEngine();
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("templating/clash/thymeleaf/");
templateResolver.setCacheable(true);
engine.setTemplateResolver(templateResolver);
StandardCacheManager cache = new StandardCacheManager();
cache.setTemplateCacheMaxSize(10);
cache.setFragmentCacheMaxSize(10);
context = new Context();
context.setVariable("todos", todos);
context.setVariable("page", "list.html");
context.setVariable("fragment", "list");
run(1);
}
@Override
public void run(int reps) {
final DevNull out = new DevNull();
for (int i = 0; i < reps; i++) {
try {
engine.process("base.html", context, out);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment