use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testHighMemoryPrecision.
@Test
public void testHighMemoryPrecision() {
double e = ApproximateHistogram.DEFAULT_PRECISION.getEpsilon();
int n = ApproximateHistogram.DEFAULT_PRECISION.getN();
int defaultDepth = ApproximateHistogram.computeDepth(e, n);
int defaultBufferSize = ApproximateHistogram.computeBufferSize(defaultDepth, n);
ApproximateHistogram hist = new ApproximateHistogram(Amount.of(1L, Data.MB));
int depth = hist.buffer.length - 1;
int bufferSize = hist.buffer[0].length;
assertTrue(depth < defaultDepth);
assertTrue(bufferSize > defaultBufferSize);
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testQueryZerothQuantile.
@Test
public void testQueryZerothQuantile() {
// Tests that querying the zeroth quantile does not throw an exception
ApproximateHistogram hist = new ApproximateHistogram(b, h);
initializeValues(hist, 10, Suppliers.ofInstance(1L));
assertEquals(1L, hist.getQuantile(0.0));
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testSmallDataCase.
@Test
public void testSmallDataCase() {
// Tests that querying the zeroth quantile does not throw an exception
ApproximateHistogram hist = new ApproximateHistogram(b, h);
initializeValues(hist, 1, Suppliers.ofInstance(1L));
assertEquals(1L, hist.getQuantile(0.5));
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testGetQuantiles.
@Test
public void testGetQuantiles() {
ApproximateHistogram hist = new ApproximateHistogram();
int n = 10;
initializeValues(hist, n, monotonic());
double[] quantiles = new double[n];
for (int i = 0; i < n; i++) {
quantiles[i] = (i + 1) / 10.0;
}
long[] results = hist.getQuantiles(quantiles);
for (int i = 0; i < n; i++) {
long res = results[i];
double q = quantiles[i];
assertEquals(hist.getQuantile(q), res);
}
}
use of com.twitter.common.stats.ApproximateHistogram in project commons by twitter.
the class ApproximateHistogramTest method testMem.
@Test
public void testMem() {
for (int b = 10; b < 100; b += 10) {
for (int h = 4; h < 16; h += 4) {
ApproximateHistogram hist = new ApproximateHistogram(b, h);
long actualSize = ObjectSizeCalculator.getObjectSize(hist);
long estimatedSize = ApproximateHistogram.memoryUsage(b, h);
assertTrue("Consume less memory than the constraint", actualSize < estimatedSize);
}
}
}
Aggregations