use of org.thymeleaf.context.ExpressionContext in project thymeleaf-tests by thymeleaf.
the class ExpressionBenchmark method main.
public static void main(String[] args) throws Exception {
final Map<String, String> expressionsMap = ExpressionBenchmarkDefinitions.createExpressionsMap();
final TemplateEngine templateEngine = new TemplateEngine();
final IEngineConfiguration configuration = templateEngine.getConfiguration();
final IExpressionContext processingContext = new ExpressionContext(configuration);
final IStandardExpressionParser parser = new StandardExpressionParser();
for (final Map.Entry<String, String> expressionEntry : expressionsMap.entrySet()) {
final String expression = expressionEntry.getKey();
final String expectedParsingResult = expressionEntry.getValue();
final IStandardExpression parsedExpression = parser.parseExpression(processingContext, expression);
Assert.assertNotNull(parsedExpression);
final String exp = parsedExpression.getStringRepresentation();
Assert.assertEquals(expectedParsingResult, exp);
}
final StopWatch sw = new StopWatch();
sw.start();
for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(processingContext, expression);
sw.stop();
System.out.println("First pass: " + sw.toString());
sw.reset();
sw.start();
for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(processingContext, expression);
sw.stop();
System.out.println("Second pass: " + sw.toString());
}
Aggregations