1 19 20 package org.openide.util; 21 22 import org.openide.utildata.UtilClass; 23 import org.netbeans.performance.Benchmark; 24 import java.util.ResourceBundle ; 25 26 public class NbBundleTest extends Benchmark { 27 28 public NbBundleTest(String name) { 29 super( name, new Integer [] { 30 new Integer (1), new Integer (10), new Integer (100), new Integer (1000) 31 }); 32 } 33 34 private String [] keys; 35 36 protected void setUp() { 37 int count = getIterationCount(); 38 int param = ((Integer )getArgument()).intValue(); 39 keys = new String [param]; 40 for( int i=0; i<param; i++ ) { 41 keys[i] = "MSG_BundleTest_" + i; 42 } 43 } 44 45 protected void tearDown() { 46 keys=null; 47 } 48 49 public void testGetMessageUsingClass() throws Exception { 50 int count = getIterationCount(); 51 int magnitude = ((Integer )getArgument()).intValue(); 52 53 while( count-- > 0 ) { 54 for( int number = 0; number < magnitude; number++ ) { 56 NbBundle.getMessage( UtilClass.class, keys[number] ); 57 } 58 } 59 } 60 61 public void testGetMessageUsingClassFullBrand() throws Exception { 62 int count = getIterationCount(); 63 int magnitude = ((Integer )getArgument()).intValue(); 64 NbBundle.setBranding("brand1"); 65 66 while( count-- > 0 ) { 67 for( int number = 0; number < magnitude; number++ ) { 69 NbBundle.getMessage( UtilClass.class, keys[number] ); 70 } 71 } 72 NbBundle.setBranding(null); 73 } 74 75 public void testGetMessageUsingEmptyBrand() throws Exception { 76 int count = getIterationCount(); 77 int magnitude = ((Integer )getArgument()).intValue(); 78 NbBundle.setBranding("brand2"); 79 80 while( count-- > 0 ) { 81 for( int number = 0; number < magnitude; number++ ) { 83 NbBundle.getMessage( UtilClass.class, keys[number] ); 84 } 85 } 86 87 NbBundle.setBranding(null); 88 } 89 90 private ResourceBundle bundle; 91 private synchronized ResourceBundle getBundle() { 92 if( bundle == null ) { 93 bundle = NbBundle.getBundle( UtilClass.class ); 94 } 95 return bundle; 96 } 97 98 private synchronized void clearBundle() { 99 bundle = null; 100 } 101 102 public void testGetMessageUsingLazyCache() throws Exception { 103 int count = getIterationCount(); 104 int magnitude = ((Integer )getArgument()).intValue(); 105 106 while( count-- > 0 ) { 107 for( int number = 0; number < magnitude; number++ ) { 109 getBundle().getString( keys[number] ); 110 } 111 clearBundle(); 112 } 113 } 114 115 public void testGetMessageUsingCachedBundle() throws Exception { 116 int count = getIterationCount(); 117 int magnitude = ((Integer )getArgument()).intValue(); 118 119 while( count-- > 0 ) { 120 ResourceBundle bundle = NbBundle.getBundle( UtilClass.class ); 121 for( int number = 0; number < magnitude; number++ ) { 123 bundle.getString( keys[number] ); 124 } 125 } 126 } 127 128 public void testGetMessageUsingCachedBundleFullBrand() throws Exception { 129 int count = getIterationCount(); 130 int magnitude = ((Integer )getArgument()).intValue(); 131 NbBundle.setBranding("brand1"); 132 133 while( count-- > 0 ) { 134 ResourceBundle bundle = NbBundle.getBundle( UtilClass.class ); 135 for( int number = 0; number < magnitude; number++ ) { 137 bundle.getString( keys[number] ); 138 } 139 } 140 NbBundle.setBranding(null); 141 } 142 143 144 public void testGetMessageUsingCachedBundleEmptyBrand() throws Exception { 145 int count = getIterationCount(); 146 int magnitude = ((Integer )getArgument()).intValue(); 147 NbBundle.setBranding("brand2"); 148 149 while( count-- > 0 ) { 150 ResourceBundle bundle = NbBundle.getBundle( UtilClass.class ); 151 for( int number = 0; number < magnitude; number++ ) { 153 bundle.getString( keys[number] ); 154 } 155 } 156 NbBundle.setBranding(null); 157 } 158 159 public static void main(String [] args) { 160 simpleRun( NbBundleTest.class ); 161 } 162 } 163 | Popular Tags |