From 7339c5da5fb0cdbc403c4fca881fcbcf6b60b994 Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 5 Jan 2010 16:48:14 +0000 Subject: [PATCH] parser speed tests --- .../tools/Java15PointcutExpressionTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java b/weaver5/java5-testsrc/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java index 47b57fe9a..9b155df3e 100644 --- a/weaver5/java5-testsrc/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java +++ b/weaver5/java5-testsrc/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java @@ -141,6 +141,67 @@ public class Java15PointcutExpressionTest extends TestCase { } + private static final Set DEFAULT_SUPPORTED_PRIMITIVES = new HashSet(); + + static { + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.EXECUTION); + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.ARGS); + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.REFERENCE); + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.THIS); + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.TARGET); + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.WITHIN); + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ANNOTATION); + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_WITHIN); + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ARGS); + DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_TARGET); + } + + public void testPerformanceOfPointcutParsing() { + String expression = "execution(public * rewards.internal.*.*Repository+.*(..))"; + long stime1 = System.currentTimeMillis(); + PointcutParser parser = PointcutParser.getPointcutParserSupportingSpecifiedPrimitivesAndUsingContextClassloaderForResolution(DEFAULT_SUPPORTED_PRIMITIVES); + long stime2 = System.currentTimeMillis(); + PointcutExpression pointcutExpression = parser.parsePointcutExpression(expression, null, new PointcutParameter[0]); + long etime = System.currentTimeMillis(); + System.out.println("Time to get a parser "+(stime2-stime1)+"ms"); + System.out.println("Time taken to parse expression is "+(etime-stime2)+"ms"); + } + + + public void testPerformanceOfPointcutParsingWithBean() { + String expression = "execution(public * rewards.internal.*.*Repository+.*(..))"; + PointcutParser parser = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingSpecifiedClassloaderForResolution(this.getClass().getClassLoader()); + BeanDesignatorHandler beanHandler = new BeanDesignatorHandler(); + parser.registerPointcutDesignatorHandler(beanHandler); + long stime = System.currentTimeMillis(); + PointcutExpression pointcutExpression = parser.parsePointcutExpression(expression, null, new PointcutParameter[0]); + long etime = System.currentTimeMillis(); + System.out.println("Time taken to parse expression is "+(etime-stime)+"ms"); + } + + private class BeanDesignatorHandler implements PointcutDesignatorHandler { + + private String askedToParse; + public boolean simulateDynamicTest = false; + + public String getDesignatorName() { + return "bean"; + } + + /* (non-Javadoc) + * @see org.aspectj.weaver.tools.PointcutDesignatorHandler#parse(java.lang.String) + */ + public ContextBasedMatcher parse(String expression) { + this.askedToParse = expression; + return null; +// return new BeanPointcutExpression(expression,this.simulateDynamicTest); + } + + public String getExpressionLastAskedToParse() { + return this.askedToParse; + } + } + /** * Test matching of pointcuts against expressions. A reflection world is being used on the backend here (not a Bcel one). -- 2.39.5