Search in sources :

Example 1 with ExpressionContext

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());
}
Also used : IEngineConfiguration(org.thymeleaf.IEngineConfiguration) StopWatch(org.apache.commons.lang3.time.StopWatch) TemplateEngine(org.thymeleaf.TemplateEngine) IExpressionContext(org.thymeleaf.context.IExpressionContext) IExpressionContext(org.thymeleaf.context.IExpressionContext) ExpressionContext(org.thymeleaf.context.ExpressionContext) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 IEngineConfiguration (org.thymeleaf.IEngineConfiguration)1 TemplateEngine (org.thymeleaf.TemplateEngine)1 ExpressionContext (org.thymeleaf.context.ExpressionContext)1 IExpressionContext (org.thymeleaf.context.IExpressionContext)1