Friday, 1 May 2015

Simple Class to Measure Latency

This is a very simple class I wrote to measure latency.  It's not the Rolls Royce solution that is HDRHistogram but if you want to add just one class to your project this does the trick quite nicely.

Here's a simple test program to show you how it's used:


This is some sample output:

Thread.sleep() random
Latency measured:
 0.32 us for 50 percentile
 0.44 us for 90 percentile
 0.68 us for 99 percentile
 26.82 us for 99.9 percentile
 582.66 us for 99.99 percentile
 2024.92 us worst percentile
Math.sqrt
Latency measured:
 0.04 us for 50 percentile
 0.06 us for 90 percentile
 0.09 us for 99 percentile
 0.12 us for 99.9 percentile
 0.20 us for 99.99 percentile
 28.17 us worst percentile

There are only 4 methods:
  • The constructor: This takes an int for the maximum number of times you want to measure. Apart from memory implications, oversizing, is not a problem.  In this implementation you need to take at least 10,000 measurements for the code to work. If you want to take less just adapt the code appropriately in printStats().
  • startMeasure() and endMeasure() are called on either side of the code to be measured.
  • printStats() prints out the results.
Implementation below:

1 comment:

  1. The weird media occasion was hoped to make some diplomatic floor by at least of|no less than} opening the door, but since not a lot progress has been made and North Korea stays a closely sanctioned nation by 점보카지노 many of the world. Several key issues have arisen as more and more jurisdictions are permitting and controlling on-line playing worldwide. These international locations take steps to keep on-line playing accountable, such as a dedicated budget for habit facilities and limits on betting quantities . Illegal operators, nonetheless, encourage customers to bet giant quantities frequently and keep away from paying taxes.

    ReplyDelete