| 1 |
/** |
| 2 |
* HistogramPerfTest.java |
| 3 |
* Written by Gil Tene of Azul Systems, and released to the public domain, |
| 4 |
* as explained at http://creativecommons.org/publicdomain/zero/1.0/ |
| 5 |
* |
| 6 |
* @author Gil Tene |
| 7 |
*/ |
| 8 |
|
| 9 |
package org.HdrHistogram; |
| 10 |
|
| 11 |
import org.junit.*; |
| 12 |
|
| 13 |
/** |
| 14 |
* JUnit test for {@link org.HdrHistogram.Histogram} |
| 15 |
*/ |
| 16 |
public class HistogramPerfTest { |
| 17 |
static final long highestTrackableValue = 3600L * 1000 * 1000; // e.g. for 1 hr in usec units |
| 18 |
static final int numberOfSignificantValueDigits = 3; |
| 19 |
static final long testValueLevel = 12340; |
| 20 |
static final long warmupLoopLength = 50000; |
| 21 |
static final long rawTimingLoopCount = 800000000L; |
| 22 |
static final long rawDoubleTimingLoopCount = 300000000L; |
| 23 |
static final long singleWriterIntervalTimingLoopCount = 100000000L; |
| 24 |
static final long singleWriterDoubleIntervalTimingLoopCount = 100000000L; |
| 25 |
static final long intervalTimingLoopCount = 40000000L; |
| 26 |
static final long synchronizedTimingLoopCount = 180000000L; |
| 27 |
static final long atomicTimingLoopCount = 80000000L; |
| 28 |
static final long concurrentTimingLoopCount = 50000000L; |
| 29 |
|
| 30 |
void recordLoop(AbstractHistogram histogram, long loopCount) { |
| 31 |
for (long i = 0; i < loopCount; i++) |
| 32 |
histogram.recordValue(testValueLevel + (i & 0x8000)); |
| 33 |
} |
| 34 |
|
| 35 |
void recordLoopWithExpectedInterval(AbstractHistogram histogram, long loopCount, long expectedInterval) { |
| 36 |
for (long i = 0; i < loopCount; i++) |
| 37 |
histogram.recordValueWithExpectedInterval(testValueLevel + (i & 0x8000), expectedInterval); |
| 38 |
} |
| 39 |
|
| 40 |
void recordLoopWithExpectedInterval(Recorder histogram, long loopCount, long expectedInterval) { |
| 41 |
for (long i = 0; i < loopCount; i++) |
| 42 |
histogram.recordValueWithExpectedInterval(testValueLevel + (i & 0x8000), expectedInterval); |
| 43 |
} |
| 44 |
|
| 45 |
void recordLoopWithExpectedInterval(SingleWriterRecorder histogram, long loopCount, long expectedInterval) { |
| 46 |
for (long i = 0; i < loopCount; i++) |
| 47 |
histogram.recordValueWithExpectedInterval(testValueLevel + (i & 0x8000), expectedInterval); |
| 48 |
} |
| 49 |
|
| 50 |
void recordLoopWithExpectedInterval(DoubleRecorder histogram, long loopCount, long expectedInterval) { |
| 51 |
for (long i = 0; i < loopCount; i++) |
| 52 |
histogram.recordValueWithExpectedInterval(testValueLevel + (i & 0x8000), expectedInterval); |
| 53 |
} |
| 54 |
|
| 55 |
void recordLoopWithExpectedInterval(SingleWriterDoubleRecorder histogram, long loopCount, long expectedInterval) { |
| 56 |
for (long i = 0; i < loopCount; i++) |
| 57 |
histogram.recordValueWithExpectedInterval(testValueLevel + (i & 0x8000), expectedInterval); |
| 58 |
} |
| 59 |
|
| 60 |
void recordLoopDoubleWithExpectedInterval(DoubleHistogram histogram, long loopCount, double expectedInterval) { |
| 61 |
for (long i = 0; i < loopCount; i++) |
| 62 |
histogram.recordValueWithExpectedInterval(testValueLevel + (i & 0x8000), expectedInterval); |
| 63 |
} |
| 64 |
|
| 65 |
long LeadingZerosSpeedLoop(long loopCount) { |
| 66 |
long sum = 0; |
| 67 |
for (long i = 0; i < loopCount; i++) { |
| 68 |
// long val = testValueLevel + (i & 0x8000); |
| 69 |
long val = testValueLevel; |
| 70 |
sum += Long.numberOfLeadingZeros(val); |
| 71 |
sum += Long.numberOfLeadingZeros(val); |
| 72 |
sum += Long.numberOfLeadingZeros(val); |
| 73 |
sum += Long.numberOfLeadingZeros(val); |
| 74 |
sum += Long.numberOfLeadingZeros(val); |
| 75 |
sum += Long.numberOfLeadingZeros(val); |
| 76 |
sum += Long.numberOfLeadingZeros(val); |
| 77 |
sum += Long.numberOfLeadingZeros(val); |
| 78 |
} |
| 79 |
return sum; |
| 80 |
} |
| 81 |
|
| 82 |
public void testRawRecordingSpeedSingleValue(String label, AbstractHistogram histogram, long timingLoopCount) throws Exception { |
| 83 |
System.out.println("\nTiming recording speed with single value per recording:"); |
| 84 |
// Warm up: |
| 85 |
long startTime = System.nanoTime(); |
| 86 |
recordLoop(histogram, warmupLoopLength); |
| 87 |
long endTime = System.nanoTime(); |
| 88 |
long deltaUsec = (endTime - startTime) / 1000L; |
| 89 |
long rate = 1000000 * warmupLoopLength / deltaUsec; |
| 90 |
System.out.println(label + "Warmup: " + warmupLoopLength + " value recordings completed in " + |
| 91 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 92 |
histogram.reset(); |
| 93 |
// Wait a bit to make sure compiler had a cache to do it's stuff: |
| 94 |
try { |
| 95 |
Thread.sleep(1000); |
| 96 |
} catch (InterruptedException e) { |
| 97 |
} |
| 98 |
startTime = System.nanoTime(); |
| 99 |
recordLoop(histogram, timingLoopCount); |
| 100 |
endTime = System.nanoTime(); |
| 101 |
deltaUsec = (endTime - startTime) / 1000L; |
| 102 |
rate = 1000000 * timingLoopCount / deltaUsec; |
| 103 |
System.out.println(label + "Hot code timing:"); |
| 104 |
System.out.println(label + timingLoopCount + " value recordings completed in " + |
| 105 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 106 |
rate = 1000000 * histogram.getTotalCount() / deltaUsec; |
| 107 |
System.out.println(label + histogram.getTotalCount() + " raw recorded entries completed in " + |
| 108 |
deltaUsec + " usec, rate = " + rate + " recorded values per sec."); |
| 109 |
} |
| 110 |
|
| 111 |
public void testRawRecordingSpeedAtExpectedInterval(String label, AbstractHistogram histogram, |
| 112 |
long expectedInterval, long timingLoopCount) throws Exception { |
| 113 |
System.out.println("\nTiming recording speed with expectedInterval = " + expectedInterval + " :"); |
| 114 |
// Warm up: |
| 115 |
long startTime = System.nanoTime(); |
| 116 |
recordLoopWithExpectedInterval(histogram, warmupLoopLength, expectedInterval); |
| 117 |
long endTime = System.nanoTime(); |
| 118 |
long deltaUsec = (endTime - startTime) / 1000L; |
| 119 |
long rate = 1000000 * warmupLoopLength / deltaUsec; |
| 120 |
System.out.println(label + "Warmup: " + warmupLoopLength + " value recordings completed in " + |
| 121 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 122 |
histogram.reset(); |
| 123 |
// Wait a bit to make sure compiler had a cache to do it's stuff: |
| 124 |
try { |
| 125 |
Thread.sleep(1000); |
| 126 |
} catch (InterruptedException e) { |
| 127 |
} |
| 128 |
startTime = System.nanoTime(); |
| 129 |
recordLoopWithExpectedInterval(histogram, timingLoopCount, expectedInterval); |
| 130 |
endTime = System.nanoTime(); |
| 131 |
deltaUsec = (endTime - startTime) / 1000L; |
| 132 |
rate = 1000000 * timingLoopCount / deltaUsec; |
| 133 |
System.out.println(label + "Hot code timing:"); |
| 134 |
System.out.println(label + timingLoopCount + " value recordings completed in " + |
| 135 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 136 |
rate = 1000000 * histogram.getTotalCount() / deltaUsec; |
| 137 |
System.out.println(label + histogram.getTotalCount() + " raw recorded entries completed in " + |
| 138 |
deltaUsec + " usec, rate = " + rate + " recorded values per sec."); |
| 139 |
} |
| 140 |
|
| 141 |
public void testRawRecordingSpeedAtExpectedInterval(String label, Recorder intervalHistogram, |
| 142 |
long expectedInterval, long timingLoopCount) throws Exception { |
| 143 |
System.out.println("\nTiming recording speed with expectedInterval = " + expectedInterval + " :"); |
| 144 |
// Warm up: |
| 145 |
long startTime = System.nanoTime(); |
| 146 |
recordLoopWithExpectedInterval(intervalHistogram, warmupLoopLength, expectedInterval); |
| 147 |
long endTime = System.nanoTime(); |
| 148 |
long deltaUsec = (endTime - startTime) / 1000L; |
| 149 |
long rate = 1000000 * warmupLoopLength / deltaUsec; |
| 150 |
System.out.println(label + "Warmup: " + warmupLoopLength + " value recordings completed in " + |
| 151 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 152 |
intervalHistogram.reset(); |
| 153 |
// Wait a bit to make sure compiler had a cache to do it's stuff: |
| 154 |
try { |
| 155 |
Thread.sleep(1000); |
| 156 |
} catch (InterruptedException e) { |
| 157 |
} |
| 158 |
startTime = System.nanoTime(); |
| 159 |
recordLoopWithExpectedInterval(intervalHistogram, timingLoopCount, expectedInterval); |
| 160 |
endTime = System.nanoTime(); |
| 161 |
deltaUsec = (endTime - startTime) / 1000L; |
| 162 |
rate = 1000000 * timingLoopCount / deltaUsec; |
| 163 |
System.out.println(label + "Hot code timing:"); |
| 164 |
System.out.println(label + timingLoopCount + " value recordings completed in " + |
| 165 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 166 |
Histogram histogram = intervalHistogram.getIntervalHistogram(); |
| 167 |
rate = 1000000 * histogram.getTotalCount() / deltaUsec; |
| 168 |
System.out.println(label + histogram.getTotalCount() + " raw recorded entries completed in " + |
| 169 |
deltaUsec + " usec, rate = " + rate + " recorded values per sec."); |
| 170 |
} |
| 171 |
|
| 172 |
public void testRawRecordingSpeedAtExpectedInterval(String label, SingleWriterRecorder intervalHistogram, |
| 173 |
long expectedInterval, long timingLoopCount) throws Exception { |
| 174 |
System.out.println("\nTiming recording speed with expectedInterval = " + expectedInterval + " :"); |
| 175 |
// Warm up: |
| 176 |
long startTime = System.nanoTime(); |
| 177 |
recordLoopWithExpectedInterval(intervalHistogram, warmupLoopLength, expectedInterval); |
| 178 |
long endTime = System.nanoTime(); |
| 179 |
long deltaUsec = (endTime - startTime) / 1000L; |
| 180 |
long rate = 1000000 * warmupLoopLength / deltaUsec; |
| 181 |
System.out.println(label + "Warmup: " + warmupLoopLength + " value recordings completed in " + |
| 182 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 183 |
intervalHistogram.reset(); |
| 184 |
// Wait a bit to make sure compiler had a cache to do it's stuff: |
| 185 |
try { |
| 186 |
Thread.sleep(1000); |
| 187 |
} catch (InterruptedException e) { |
| 188 |
} |
| 189 |
startTime = System.nanoTime(); |
| 190 |
recordLoopWithExpectedInterval(intervalHistogram, timingLoopCount, expectedInterval); |
| 191 |
endTime = System.nanoTime(); |
| 192 |
deltaUsec = (endTime - startTime) / 1000L; |
| 193 |
rate = 1000000 * timingLoopCount / deltaUsec; |
| 194 |
System.out.println(label + "Hot code timing:"); |
| 195 |
System.out.println(label + timingLoopCount + " value recordings completed in " + |
| 196 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 197 |
Histogram histogram = intervalHistogram.getIntervalHistogram(); |
| 198 |
rate = 1000000 * histogram.getTotalCount() / deltaUsec; |
| 199 |
System.out.println(label + histogram.getTotalCount() + " raw recorded entries completed in " + |
| 200 |
deltaUsec + " usec, rate = " + rate + " recorded values per sec."); |
| 201 |
} |
| 202 |
|
| 203 |
public void testRawRecordingSpeedAtExpectedInterval(String label, SingleWriterDoubleRecorder intervalHistogram, |
| 204 |
long expectedInterval, long timingLoopCount) throws Exception { |
| 205 |
System.out.println("\nTiming recording speed with expectedInterval = " + expectedInterval + " :"); |
| 206 |
// Warm up: |
| 207 |
long startTime = System.nanoTime(); |
| 208 |
recordLoopWithExpectedInterval(intervalHistogram, warmupLoopLength, expectedInterval); |
| 209 |
long endTime = System.nanoTime(); |
| 210 |
long deltaUsec = (endTime - startTime) / 1000L; |
| 211 |
long rate = 1000000 * warmupLoopLength / deltaUsec; |
| 212 |
System.out.println(label + "Warmup: " + warmupLoopLength + " value recordings completed in " + |
| 213 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 214 |
intervalHistogram.reset(); |
| 215 |
// Wait a bit to make sure compiler had a cache to do it's stuff: |
| 216 |
try { |
| 217 |
Thread.sleep(1000); |
| 218 |
} catch (InterruptedException e) { |
| 219 |
} |
| 220 |
startTime = System.nanoTime(); |
| 221 |
recordLoopWithExpectedInterval(intervalHistogram, timingLoopCount, expectedInterval); |
| 222 |
endTime = System.nanoTime(); |
| 223 |
deltaUsec = (endTime - startTime) / 1000L; |
| 224 |
rate = 1000000 * timingLoopCount / deltaUsec; |
| 225 |
System.out.println(label + "Hot code timing:"); |
| 226 |
System.out.println(label + timingLoopCount + " value recordings completed in " + |
| 227 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 228 |
DoubleHistogram histogram = intervalHistogram.getIntervalHistogram(); |
| 229 |
rate = 1000000 * histogram.getTotalCount() / deltaUsec; |
| 230 |
System.out.println(label + histogram.getTotalCount() + " raw recorded entries completed in " + |
| 231 |
deltaUsec + " usec, rate = " + rate + " recorded values per sec."); |
| 232 |
} |
| 233 |
|
| 234 |
public void testRawRecordingSpeedAtExpectedInterval(String label, DoubleRecorder intervalHistogram, |
| 235 |
long expectedInterval, long timingLoopCount) throws Exception { |
| 236 |
System.out.println("\nTiming recording speed with expectedInterval = " + expectedInterval + " :"); |
| 237 |
// Warm up: |
| 238 |
long startTime = System.nanoTime(); |
| 239 |
recordLoopWithExpectedInterval(intervalHistogram, warmupLoopLength, expectedInterval); |
| 240 |
long endTime = System.nanoTime(); |
| 241 |
long deltaUsec = (endTime - startTime) / 1000L; |
| 242 |
long rate = 1000000 * warmupLoopLength / deltaUsec; |
| 243 |
System.out.println(label + "Warmup: " + warmupLoopLength + " value recordings completed in " + |
| 244 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 245 |
intervalHistogram.reset(); |
| 246 |
// Wait a bit to make sure compiler had a cache to do it's stuff: |
| 247 |
try { |
| 248 |
Thread.sleep(1000); |
| 249 |
} catch (InterruptedException e) { |
| 250 |
} |
| 251 |
startTime = System.nanoTime(); |
| 252 |
recordLoopWithExpectedInterval(intervalHistogram, timingLoopCount, expectedInterval); |
| 253 |
endTime = System.nanoTime(); |
| 254 |
deltaUsec = (endTime - startTime) / 1000L; |
| 255 |
rate = 1000000 * timingLoopCount / deltaUsec; |
| 256 |
System.out.println(label + "Hot code timing:"); |
| 257 |
System.out.println(label + timingLoopCount + " value recordings completed in " + |
| 258 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 259 |
DoubleHistogram histogram = intervalHistogram.getIntervalHistogram(); |
| 260 |
rate = 1000000 * histogram.getTotalCount() / deltaUsec; |
| 261 |
System.out.println(label + histogram.getTotalCount() + " raw recorded entries completed in " + |
| 262 |
deltaUsec + " usec, rate = " + rate + " recorded values per sec."); |
| 263 |
} |
| 264 |
|
| 265 |
public void testRawDoubleRecordingSpeedAtExpectedInterval(String label, DoubleHistogram histogram, |
| 266 |
long expectedInterval, long timingLoopCount) throws Exception { |
| 267 |
System.out.println("\nTiming recording speed with expectedInterval = " + expectedInterval + " :"); |
| 268 |
// Warm up: |
| 269 |
long startTime = System.nanoTime(); |
| 270 |
recordLoopDoubleWithExpectedInterval(histogram, warmupLoopLength, expectedInterval); |
| 271 |
long endTime = System.nanoTime(); |
| 272 |
long deltaUsec = (endTime - startTime) / 1000L; |
| 273 |
long rate = 1000000 * warmupLoopLength / deltaUsec; |
| 274 |
System.out.println(label + "Warmup: " + warmupLoopLength + " value recordings completed in " + |
| 275 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 276 |
histogram.reset(); |
| 277 |
// Wait a bit to make sure compiler had a cache to do it's stuff: |
| 278 |
try { |
| 279 |
Thread.sleep(1000); |
| 280 |
} catch (InterruptedException e) { |
| 281 |
} |
| 282 |
startTime = System.nanoTime(); |
| 283 |
recordLoopDoubleWithExpectedInterval(histogram, timingLoopCount, expectedInterval); |
| 284 |
endTime = System.nanoTime(); |
| 285 |
deltaUsec = (endTime - startTime) / 1000L; |
| 286 |
rate = 1000000 * timingLoopCount / deltaUsec; |
| 287 |
System.out.println(label + "Hot code timing:"); |
| 288 |
System.out.println(label + timingLoopCount + " value recordings completed in " + |
| 289 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 290 |
rate = 1000000 * histogram.getTotalCount() / deltaUsec; |
| 291 |
System.out.println(label + histogram.getTotalCount() + " raw recorded entries completed in " + |
| 292 |
deltaUsec + " usec, rate = " + rate + " recorded values per sec."); |
| 293 |
} |
| 294 |
|
| 295 |
@Test |
| 296 |
public void testRawRecordingSpeedSingleValue() throws Exception { |
| 297 |
AbstractHistogram histogram; |
| 298 |
histogram = new Histogram(highestTrackableValue, numberOfSignificantValueDigits); |
| 299 |
System.out.println("\n\nTiming Histogram:"); |
| 300 |
testRawRecordingSpeedSingleValue("Histogram: ", histogram, rawTimingLoopCount); |
| 301 |
} |
| 302 |
|
| 303 |
@Test |
| 304 |
public void testRawRecordingSpeed() throws Exception { |
| 305 |
AbstractHistogram histogram; |
| 306 |
histogram = new Histogram(highestTrackableValue, numberOfSignificantValueDigits); |
| 307 |
System.out.println("\n\nTiming Histogram:"); |
| 308 |
testRawRecordingSpeedAtExpectedInterval("Histogram: ", histogram, 1000000000, rawTimingLoopCount); |
| 309 |
} |
| 310 |
|
| 311 |
@Test |
| 312 |
public void testSingleWriterIntervalRecordingSpeed() throws Exception { |
| 313 |
SingleWriterRecorder histogramRecorder; |
| 314 |
histogramRecorder = new SingleWriterRecorder(highestTrackableValue, numberOfSignificantValueDigits); |
| 315 |
System.out.println("\n\nTiming SingleWriterIntervalHistogramRecorder:"); |
| 316 |
testRawRecordingSpeedAtExpectedInterval("SingleWriterRecorder: ", histogramRecorder, 1000000000, singleWriterIntervalTimingLoopCount); |
| 317 |
} |
| 318 |
|
| 319 |
@Test |
| 320 |
public void testIntervalRecordingSpeed() throws Exception { |
| 321 |
Recorder histogramRecorder; |
| 322 |
histogramRecorder = new Recorder(highestTrackableValue, numberOfSignificantValueDigits); |
| 323 |
System.out.println("\n\nTiming IntervalHistogramRecorder:"); |
| 324 |
testRawRecordingSpeedAtExpectedInterval("Recorder: ", histogramRecorder, 1000000000, intervalTimingLoopCount); |
| 325 |
} |
| 326 |
|
| 327 |
@Test |
| 328 |
public void testRawDoubleRecordingSpeed() throws Exception { |
| 329 |
DoubleHistogram histogram; |
| 330 |
histogram = new DoubleHistogram(highestTrackableValue, numberOfSignificantValueDigits); |
| 331 |
System.out.println("\n\nTiming DoubleHistogram:"); |
| 332 |
testRawDoubleRecordingSpeedAtExpectedInterval("DoubleHistogram: ", histogram, 1000000000, rawDoubleTimingLoopCount); |
| 333 |
} |
| 334 |
|
| 335 |
@Test |
| 336 |
public void testDoubleIntervalRecordingSpeed() throws Exception { |
| 337 |
DoubleRecorder histogramRecorder; |
| 338 |
histogramRecorder = new DoubleRecorder(highestTrackableValue, numberOfSignificantValueDigits); |
| 339 |
System.out.println("\n\nTiming IntervalDoubleHistogramRecorder:"); |
| 340 |
testRawRecordingSpeedAtExpectedInterval("DoubleRecorder: ", histogramRecorder, 1000000000, intervalTimingLoopCount); |
| 341 |
} |
| 342 |
|
| 343 |
@Test |
| 344 |
public void testSingleWriterDoubleIntervalRecordingSpeed() throws Exception { |
| 345 |
SingleWriterDoubleRecorder histogramRecorder; |
| 346 |
histogramRecorder = new SingleWriterDoubleRecorder(highestTrackableValue, numberOfSignificantValueDigits); |
| 347 |
System.out.println("\n\nTiming SingleWriterIntervalDoubleHistogramRecorder:"); |
| 348 |
testRawRecordingSpeedAtExpectedInterval("SingleWriterDoubleRecorder: ", histogramRecorder, 1000000000, singleWriterDoubleIntervalTimingLoopCount); |
| 349 |
} |
| 350 |
|
| 351 |
@Test |
| 352 |
public void testRawSyncronizedRecordingSpeed() throws Exception { |
| 353 |
AbstractHistogram histogram; |
| 354 |
histogram = new SynchronizedHistogram(highestTrackableValue, numberOfSignificantValueDigits); |
| 355 |
System.out.println("\n\nTiming SynchronizedHistogram:"); |
| 356 |
testRawRecordingSpeedAtExpectedInterval("SynchronizedHistogram: ", histogram, 1000000000, synchronizedTimingLoopCount); |
| 357 |
} |
| 358 |
|
| 359 |
@Test |
| 360 |
public void testRawAtomicRecordingSpeed() throws Exception { |
| 361 |
AbstractHistogram histogram; |
| 362 |
histogram = new AtomicHistogram(highestTrackableValue, numberOfSignificantValueDigits); |
| 363 |
System.out.println("\n\nTiming AtomicHistogram:"); |
| 364 |
testRawRecordingSpeedAtExpectedInterval("AtomicHistogram: ", histogram, 1000000000, atomicTimingLoopCount); |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
@Test |
| 369 |
public void testRawConcurrentRecordingSpeed() throws Exception { |
| 370 |
AbstractHistogram histogram; |
| 371 |
histogram = new ConcurrentHistogram(highestTrackableValue, numberOfSignificantValueDigits); |
| 372 |
System.out.println("\n\nTiming ConcurrentHistogram:"); |
| 373 |
testRawRecordingSpeedAtExpectedInterval("AtomicHistogram: ", histogram, 1000000000, concurrentTimingLoopCount); |
| 374 |
} |
| 375 |
|
| 376 |
public void testLeadingZerosSpeed() throws Exception { |
| 377 |
System.out.println("\nTiming LeadingZerosSpeed :"); |
| 378 |
long startTime = System.nanoTime(); |
| 379 |
LeadingZerosSpeedLoop(warmupLoopLength); |
| 380 |
long endTime = System.nanoTime(); |
| 381 |
long deltaUsec = (endTime - startTime) / 1000L; |
| 382 |
long rate = 1000000 * warmupLoopLength / deltaUsec; |
| 383 |
System.out.println("Warmup:\n" + warmupLoopLength + " Leading Zero loops completed in " + |
| 384 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 385 |
// Wait a bit to make sure compiler had a cache to do it's stuff: |
| 386 |
try { |
| 387 |
Thread.sleep(1000); |
| 388 |
} catch (InterruptedException e) { |
| 389 |
} |
| 390 |
startTime = System.nanoTime(); |
| 391 |
LeadingZerosSpeedLoop(rawTimingLoopCount); |
| 392 |
endTime = System.nanoTime(); |
| 393 |
deltaUsec = (endTime - startTime) / 1000L; |
| 394 |
rate = 1000000 * rawTimingLoopCount / deltaUsec; |
| 395 |
System.out.println("Hot code timing:"); |
| 396 |
System.out.println(rawTimingLoopCount + " Leading Zero loops completed in " + |
| 397 |
deltaUsec + " usec, rate = " + rate + " value recording calls per sec."); |
| 398 |
} |
| 399 |
|
| 400 |
public static void main(String[] args) { |
| 401 |
try { |
| 402 |
HistogramPerfTest test = new HistogramPerfTest(); |
| 403 |
test.testLeadingZerosSpeed(); |
| 404 |
Thread.sleep(1000000); |
| 405 |
} catch (Exception e) { |
| 406 |
System.out.println("Exception: " + e); |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
} |