UNPKG

monti-apm-sketches-js

Version:

An Implementation Of DDSketch, A Fast and Fully-Mergeable Quantile Sketch with Relative-Error Guarantees.

41 lines (33 loc) 869 B
const assert = require('assert'); const fs = require('fs'); const path = require('path'); const DDSketch = require('../index').DDSketch; // Expected quantile values computed with the official sketches-go // implementation. const DATA = [ { // 1000 numbers that follow a lognormal distribution fn: 'lognormal-n1000-1.txt', qs: { 0.5: 55552, 0.75: 119980, 0.9: 220817, 0.99: 650241 } } ] it('Correctness', () => { DATA.forEach(function(o) { const xs = fs.readFileSync(path.resolve(__dirname, 'data', o.fn), 'utf8') .split(',') .map((x) => parseInt(x)); const sketch = new DDSketch({ alpha: 0.005 }); xs.forEach((x) => { sketch.add(x); }); Object.keys(o.qs).forEach((q) => { const v = Math.floor(sketch.quantile(q)); assert.ok(v === o.qs[q]); }); }); });