Search in sources :

Example 1 with IProcessingContext

use of org.thymeleaf.context.IProcessingContext 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 Configuration configuration = new Configuration();
    final IProcessingContext processingContext = new ProcessingContext(new Context());
    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(configuration, 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(configuration, 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(configuration, processingContext, expression);
    sw.stop();
    System.out.println("Second pass: " + sw.toString());
}
Also used : IProcessingContext(org.thymeleaf.context.IProcessingContext) ProcessingContext(org.thymeleaf.context.ProcessingContext) Context(org.thymeleaf.context.Context) IProcessingContext(org.thymeleaf.context.IProcessingContext) ProcessingContext(org.thymeleaf.context.ProcessingContext) Configuration(org.thymeleaf.Configuration) IProcessingContext(org.thymeleaf.context.IProcessingContext) StopWatch(org.apache.commons.lang3.time.StopWatch) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 Configuration (org.thymeleaf.Configuration)1 Context (org.thymeleaf.context.Context)1 IProcessingContext (org.thymeleaf.context.IProcessingContext)1 ProcessingContext (org.thymeleaf.context.ProcessingContext)1