JavaScript library with implementations of multiple streaming percentile algorithms
Clone or download
Latest commit fd9c0e9 Mar 9, 2018

Streaming Percentiles

This is a reusable JavaScript library with implementations of various percentile algorithms on streams of data. These algorithms all calculate only approximate percentiles, not exact percentiles.

For more on streaming percentiles, see Calculating Percentiles on Streaming Data.


If you use NPM, npm install streaming-percentiles. Otherwise, download the latest release binaries or the latest release source code. You can also load directly from

For convenience, you can also use the latest release binaries directly from a web browser:

<script src="//"></script>
var gk = new streamingPercentiles.GK(0.1);


Here's a simple example on how to use the Greenwald-Khanna streaming percentile algorithm:

var sp = require('streaming-percentiles');

// epsilon is allowable error.  As epsilon becomes smaller, the
// accuracy of the approximations improves, but the class consumes
// more memory.
var epsilon = 0.1;
var gk = new sp.GK(epsilon);
for (var i = 0; i < 1000; ++i)
var p50 = gk.quantile(0.5); // Approx. median
var p95 = gk.quantile(0.95); // Approx. 95th percentile

API Reference

class GK(epsilon)

Construct an object which implements the Greenwald-Khanna streaming percentile algorithm with allowable error epsilon.


var sp = require('streaming-percentiles');
var gk = new sp.GK(0.1);


Logs the observation of a value.




Compute the approximate quantile at phi. For example, the 95th percentile corresponds to phi = 0.95.


var p50 = gk.quantile(0.5);


This project is licensed under the MIT License.