Added
Link Here
|
1 |
/* ******************************************************************* |
2 |
* Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). |
3 |
* All rights reserved. |
4 |
* This program and the accompanying materials are made available |
5 |
* under the terms of the Common Public License v1.0 |
6 |
* which accompanies this distribution and is available at |
7 |
* http://www.eclipse.org/legal/cpl-v10.html |
8 |
* |
9 |
* Contributors: |
10 |
* PARC initial implementation |
11 |
* ******************************************************************/ |
12 |
|
13 |
|
14 |
package org.aspectj.weaver.patterns; |
15 |
|
16 |
import junit.framework.TestCase; |
17 |
|
18 |
import org.aspectj.lang.JoinPoint; |
19 |
import org.aspectj.lang.Signature; |
20 |
import org.aspectj.runtime.reflect.Factory; |
21 |
import org.aspectj.util.FuzzyBoolean; |
22 |
|
23 |
/** |
24 |
* @author Eric Bodden |
25 |
* |
26 |
* Runs performance tests measuring lazy evaluation of |
27 |
* pointcut matching. |
28 |
*/ |
29 |
public class AndOrPerformanceTestCase extends TestCase { |
30 |
private static final int INNER_ITERATIONS = 100000; |
31 |
private static final int GLOBAL_ITERATIONS = 10; |
32 |
/** |
33 |
* Constructor for PatternTestCase. |
34 |
* @param name |
35 |
*/ |
36 |
public AndOrPerformanceTestCase(String name) { |
37 |
super(name); |
38 |
} |
39 |
|
40 |
public void testLazyEvalPerformance() { |
41 |
|
42 |
Pointcut foo = makePointcut("this(org.aspectj.weaver.patterns.AndOrPerformanceTestCase.Foo)").resolve(); |
43 |
Pointcut bar = makePointcut("this(org.aspectj.weaver.patterns.AndOrPerformanceTestCase.Bar)").resolve(); |
44 |
Pointcut c = makePointcut("this(org.aspectj.weaver.patterns.AndOrPerformanceTestCase.C)").resolve(); |
45 |
|
46 |
Factory f = new Factory("AndOrNotTestCase.java",AndOrPerformanceTestCase.class); |
47 |
|
48 |
Signature methodSig = f.makeMethodSig("void aMethod()"); |
49 |
JoinPoint.StaticPart jpsp = f.makeSJP(JoinPoint.METHOD_EXECUTION,methodSig,1); |
50 |
JoinPoint jp = Factory.makeJP(jpsp,new Foo(),new Foo()); |
51 |
|
52 |
long speedUp=0; |
53 |
long timeNonLazy=Long.MAX_VALUE; |
54 |
|
55 |
for(int iterations=0; iterations<GLOBAL_ITERATIONS; iterations++) { |
56 |
for(int caze=0; caze<2; caze++) { |
57 |
Pointcut.USE_LAZY_EVAL = (caze==1); |
58 |
long before = System.currentTimeMillis(); |
59 |
for(int runs=0; runs<INNER_ITERATIONS; runs++) { |
60 |
checkMatches(new AndPointcut(foo,bar),jp,null,FuzzyBoolean.NO); |
61 |
checkMatches(new AndPointcut(foo,foo),jp,null,FuzzyBoolean.YES); |
62 |
checkMatches(new AndPointcut(bar,foo),jp,null,FuzzyBoolean.NO); |
63 |
checkMatches(new AndPointcut(bar,c),jp,null,FuzzyBoolean.NO); |
64 |
|
65 |
//checkMatches(new OrPointcut(foo,bar),jp,null,FuzzyBoolean.YES); |
66 |
//checkMatches(new OrPointcut(foo,foo),jp,null,FuzzyBoolean.YES); |
67 |
//checkMatches(new OrPointcut(bar,foo),jp,null,FuzzyBoolean.YES); |
68 |
//checkMatches(new OrPointcut(bar,c),jp,null,FuzzyBoolean.NO); |
69 |
} |
70 |
long time = System.currentTimeMillis()-before; |
71 |
if(caze==0) { |
72 |
System.out.println("Non-Lazy Pointcut Matching took "+time+"ms"); |
73 |
timeNonLazy = time; |
74 |
} else { |
75 |
System.out.println("Lazy Pointcut Matching took "+time+"ms"); |
76 |
System.out.println("Speedup: "+(timeNonLazy-time)+"ms"); |
77 |
speedUp += timeNonLazy-time; |
78 |
} |
79 |
} |
80 |
} |
81 |
|
82 |
assertTrue("Lazy evaluation should be faster than non-lazy one.",speedUp>0); |
83 |
} |
84 |
|
85 |
private Pointcut makePointcut(String pattern) { |
86 |
return new PatternParser(pattern).parsePointcut(); |
87 |
} |
88 |
|
89 |
private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) { |
90 |
assertEquals(expected,p.match(jp,jpsp)); |
91 |
} |
92 |
|
93 |
private static class Foo{}; |
94 |
private static class Bar{}; |
95 |
private static class C{}; |
96 |
|
97 |
} |