1 7 package measurements.suites; 8 9 import junit.framework.Test; 11 import ch.ethz.inf.util.junit.PerformanceTest; 12 import ch.ethz.inf.util.junit.PerformanceTestSuite; 13 import ch.ethz.prose.Aspect; 14 import ch.ethz.prose.ProseSystem; 15 16 17 26 public 27 class BenchmarkMeasurement extends PerformanceTest { 28 29 { RANGE = new int[]{1000000};} 31 TestClass measurementObject; 32 TestClass calibrationObject; 33 boolean useProse = true; 34 35 36 boolean callDummyMethod = false; 37 void dummyMethod(boolean callRecursively) 38 { 39 if (callRecursively) 40 dummyMethod(callRecursively); 41 } 42 43 47 public BenchmarkMeasurement(String name) 48 { 49 super(name); 50 } 51 52 55 protected 56 void setUp() throws Exception 57 { 58 String proseParam = System.getProperty("useprose", 59 "" + isDebuggerEnabled()); 60 useProse = proseParam.toUpperCase().equals("TRUE"); 61 62 if (isDebuggerEnabled()) 63 RANGE=new int[]{10000}; 64 measurementObject = new TestClass1(); 65 calibrationObject = new TestClassCalibration1(); 66 String aspectToInsert = System.getProperty("aspect"); 67 if (aspectToInsert == null) 68 { 69 return; 70 } 71 72 if (useProse) 73 { 74 Aspect x = null; 75 ProseSystem.startup(); 76 77 if ("EfficientExtension".equals(aspectToInsert)) 78 x = new EfficientExtension(); 79 else if ("EfficientEntryExtension".equals(aspectToInsert)) 80 x = new EfficientEntryExtension(); 81 else if ("EfficientExitExtension".equals(aspectToInsert)) 82 x = new EfficientExitExtension(); 83 else 84 x = null; 85 86 if (x!= null) 87 ProseSystem.getAspectManager().insert(x); 88 } 89 else 90 { 91 92 if ("EfficientAspect".equals(aspectToInsert)) 94 { 95 measurementObject = new TestClass2(); 96 97 calibrationObject = new TestClassCalibration2(); 98 99 } 100 else if ("EfficientEntryAspect".equals(aspectToInsert)) 101 { 102 measurementObject = new TestClass3(); 103 104 calibrationObject = new TestClassCalibration3(); 105 } 106 else if ("EfficientExitAspect".equals(aspectToInsert)) 107 { 108 measurementObject = new TestClass4(); 109 110 calibrationObject = new TestClassCalibration4(); 111 } 112 else 113 throw new RuntimeException ("BenchmarkMeasurement.setUp:Illegal value for 'aspect'"); 114 115 } 116 } 117 118 120 protected void tearDown() throws Exception 121 { 122 if (useProse) 123 ProseSystem.teardown(); 124 } 125 126 public void test10FieldAdvice() 127 { 128 startChronometer(); 129 for (int i=0; i< RUNS; i++) 130 { 131 measurementObject.testFieldOperations(); 132 } 133 } 134 135 public void test10FieldCalibration() 136 { 137 startChronometer(); 138 for (int i=0; i< RUNS; i++) 139 { 140 calibrationObject.testFieldOperations(); 141 } 142 } 143 144 public void test11MethodAdvice() 145 { 146 RUNS=100000; 147 startChronometer(); 148 for (int i=0; i< RUNS; i++) 149 { 150 measurementObject.testMethodOperations(); 151 } 152 } 153 154 public void test11MethodCalibration() 155 { 156 startChronometer(); 157 for (int i=0; i< RUNS; i++) 158 { 159 calibrationObject.testMethodOperations(); 160 } 161 } 162 163 public void test12NoAdvice() 164 { 165 startChronometer(); 166 for (int i=0; i< RUNS; i++) 167 { 168 measurementObject.testNonJPOperations(); 169 } 170 } 171 172 public void test12NoAdviceCalibration() 173 { 174 startChronometer(); 175 for (int i=0; i< RUNS; i++) 176 { 177 calibrationObject.testNonJPOperations(); 178 } 179 } 180 181 public void test00CalibrationCall() 182 { 183 startChronometer(); 184 for(int i = 0; i < RUNS; i++) 185 { 186 if (callDummyMethod) 187 { dummyMethod(callDummyMethod); } 188 } 189 } 190 191 public void test01InterfaceCallShort() 192 { 193 194 TestInterface interfaceObject = measurementObject; 195 startChronometer(); 196 for (int i=0; i < RUNS; i++) 197 { 198 interfaceObject.interfaceMethodShort(); 199 } 200 } 201 202 public void test01InterfaceCallLong() 203 { 204 String x = "hello"; 205 TestInterface interfaceObject = measurementObject; 206 startChronometer(); 207 for (int i=0; i < RUNS; i++) 208 { 209 interfaceObject.interfaceMethodLong(x,x); 210 } 211 } 212 213 214 215 public void test02VirtualCallShort() 216 { 217 startChronometer(); 218 for (int i=0; i < RUNS; i++) 219 { 220 measurementObject.instanceMethodShort(); 221 } 222 } 223 224 public void test02VirtualCallLong() 225 { 226 String x = "String"; 227 startChronometer(); 228 for (int i=0; i < RUNS; i++) 229 { 230 measurementObject.instanceMethodLong(x,x); 231 } 232 } 233 234 235 236 public void test03SyncVirtualCallShort() 237 { 238 startChronometer(); 239 for (int i=0; i < RUNS; i++) 240 { 241 measurementObject.syncInstanceMethodShort(); 242 } 243 } 244 245 public void test03SyncVirtualCallLong() 246 { 247 String x = "String"; 248 startChronometer(); 249 for (int i=0; i < RUNS; i++) 250 { 251 measurementObject.syncInstanceMethodLong(x,x); 252 } 253 } 254 255 public void test04PutField() 256 { 257 startChronometer(); 258 259 measurementObject.testPutField(RUNS); 260 } 261 262 public void test04PutFieldCalibration() 263 { 264 startChronometer(); 265 calibrationObject.testPutField(RUNS); 266 } 267 268 public void test05GetField() 269 {startChronometer(); 270 measurementObject.testGetField(RUNS); 271 } 272 273 public void test05GetFieldCalibration() 274 {startChronometer(); 275 calibrationObject.testGetField(RUNS); 276 } 277 278 279 280 284 public static 285 Test suite() 286 { 287 return new PerformanceTestSuite(BenchmarkMeasurement.class); 288 } 289 290 } 291 292 293 | Popular Tags |