Coder Social home page Coder Social logo

ccollie / native-hdr-histogram Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mcollina/native-hdr-histogram

0.0 1.0 0.0 458 KB

node.js bindings for hdr histogram C implementation

License: Other

Python 0.43% C++ 1.72% JavaScript 0.78% CMake 1.34% C 86.09% Makefile 2.06% DIGITAL Command Language 3.74% Perl 0.55% Batchfile 0.16% Shell 0.40% Roff 0.63% Objective-C 2.09%

native-hdr-histogram's Introduction

native-hdr-histogram

node.js bindings for hdr histogram C implementation(version 0.9.10).

Build status Build Status

HDR Histogram is designed for recoding histograms of value measurements in latency and performance sensitive applications. Measurements show value recording times as low as 3-6 nanoseconds on modern (circa 2014) Intel CPUs. A Histogram's memory footprint is constant, with no allocation operations involved in recording data values or in iterating through them.

This library is blazingly fast, and you can use it to record histograms with no overhead. Linux, Mac OS X and Windows are all supported.

Install

npm i native-hdr-histogram --save

If you see any errors, you might need to configure your system to compile native addons: follow the instructions at node-gyp.

Example

'use strict'

const Histogram = require('native-hdr-histogram')
const max = 1000000
const key = 'record*' + max
const histogram = new Histogram(1, 100)

console.time(key)
for (let i = 0; i < max; i++) {
  histogram.record(Math.floor((Math.random() * 42 + 1)))
}
console.timeEnd(key)

console.log('80 percentile is', histogram.percentile(80))
console.log('99 percentile is', histogram.percentile(99))

console.log(histogram.percentiles())

API


Histogram(lowest, max, figures)

Create a new histogram with:

  • lowest: is the lowest possible number that can be recorded (default 1).
  • max: is the maximum number that can be recorded (default 100).
  • figures: the number of figures in a decimal number that will be maintained, must be between 1 and 5 (inclusive) (default 3).

histogram.record(value)

Record value in the histogram. Returns true if the recording was successful, false otherwise.


histogram.min()

Return the minimum value recorded in the histogram.


histogram.max()

Return the maximum value recorded in the histogram.


histogram.mean()

Return the mean of the histogram.


histogram.stddev()

Return the standard deviation of the histogram.


histogram.percentile(percentile)

Returns the value at the given percentile. percentile must be > 0 and <= 100, otherwise it will throw.


histogram.percentiles()

Returns all the percentiles.

Sample output:

[ { percentile: 0, value: 1 },
  { percentile: 50, value: 22 },
  { percentile: 75, value: 32 },
  { percentile: 87.5, value: 37 },
  { percentile: 93.75, value: 40 },
  { percentile: 96.875, value: 41 },
  { percentile: 98.4375, value: 42 },
  { percentile: 100, value: 42 } ]

histogram.encode()

Returns a Buffer containing a serialized version of the histogram


histogram.decode(buf)

Reads a Buffer and deserialize an histogram.


histogram.reset()

Resets the histogram so it can be reused.

Acknowledgements

This project was kindly sponsored by nearForm.

The pre-compilation work of this project is only possible because of mapbox's amazing work on node-pre-gyp. A lot of the functionality enabled is following the example set by their node-sqlite3 library.

License

This library is licensed as MIT

HdrHistogram_c is licensed as BSD license

zlib is licensed as zlib License

The scripts used in the scripts folder are modified BSD licensed scripts from the node-sqlite3 libary.

native-hdr-histogram's People

Contributors

ahwayakchih avatar bzoz avatar glentiki avatar mcollina avatar vweevers avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.