1 19 20 package org.openide.util.lookup; 21 22 import org.netbeans.performance.Benchmark; 23 import java.util.*; 24 import org.openide.util.Lookup; 25 import org.openide.util.lookup.*; 26 27 35 public class ProxyLookupTest extends Benchmark { 36 37 public ProxyLookupTest(String name) { 38 super( name, new String [] {"tree3", "tree2", "flat"} ); 39 } 40 41 private Lookup lookup; 42 43 protected void setUp() { 44 String type = (String )getArgument(); 45 if("tree3".equals(type)) { 46 lookup = new ProxyLookup( new Lookup[] { 47 new ProxyLookup( new Lookup[] { 48 createProxy(4), 49 createProxy(4) 50 }), 51 new ProxyLookup( new Lookup[] { 52 createProxy(4), 53 createProxy(4) 54 }) 55 }); 56 } else if("tree2".equals(type)) { 57 lookup = new ProxyLookup( new Lookup[] { 58 createProxy(8), 59 createProxy(8) 60 }); 61 } else { 62 lookup = createProxy(16); 63 } 64 } 65 66 private Lookup createOne() { 67 InstanceContent ic = new InstanceContent(); 68 ic.add(new Object ()); 69 ic.add(""); 70 return new AbstractLookup(ic); 71 } 72 73 private Lookup createProxy(int subs) { 74 Lookup[] delegates = new Lookup[subs]; 75 for(int i=0; i<subs; i++) delegates[i] = createOne(); 76 return new ProxyLookup(delegates); 77 } 78 79 protected void tearDown() { 80 lookup=null; 81 } 82 83 public void testLookupObject() throws Exception { 84 int count = getIterationCount(); 85 86 while( count-- > 0 ) { 87 lookup.lookup(Object .class); 89 } 90 } 91 92 public void testLookupString() throws Exception { 93 int count = getIterationCount(); 94 95 while( count-- > 0 ) { 96 lookup.lookup(String .class); 98 } 99 } 100 101 public void testAllInstances() throws Exception { 102 int count = getIterationCount(); 103 Lookup.Result result = lookup.lookup(new Lookup.Template(String .class)); 104 105 while( count-- > 0 ) { 106 Collection c = result.allInstances(); 108 } 109 } 110 111 public void testIterateInstances() throws Exception { 112 int count = getIterationCount(); 113 Lookup.Result result = lookup.lookup(new Lookup.Template(String .class)); 114 115 while( count-- > 0 ) { 116 Iterator i = result.allInstances().iterator(); 118 while (i.hasNext()) i.next(); 119 } 120 } 121 122 public static void main( String [] args ) { 123 junit.textui.TestRunner.run( new junit.framework.TestSuite( ProxyLookupTest.class ) ); 124 } 125 } 126 | Popular Tags |