Skip to content

TheProfs/recordable

Repository files navigation

test-workflow codeql-workflow

⌚ recordable

recordable & plottable histogram

Install

npm i https://github.com/TheProfs/recordable.git

Usage

Basic

import { Recordable } from 'recordable'

const histogram = new Recordable()

for (let i = 0; i < 600; i++)
  histogram.record(Math.round(Math.random() * 20) + 1)

console.log(histogram.count)
// count of invocations
// 600

console.log(histogram.min)
// minimum recorded value
// 3.05 ms

console.log(histogram.max)
// maximum recorded value
// 85.17 m

console.log(histogram.mean)
// Arithmetic mean/average
// 11.42 ms

console.log(histogram.stddev)
// statistical standard deviation between all values
// 5.17 ms

Available methods

histogram.record(value)

record a value

histogram.tick()

record a value of 1

histogram.recordDelta(label)

record the time-delta (Δt) between invocations with the same label value.
Can be called without a label parameter, in which case it records the time-delta since the last invocation without a label parameter.

histogram.reset()

does exactly what you think it does

histogram.plot()

produce an ASCII plot of the mean of all values.
See below.

Plotting

import { Recordable } from 'recordable'

const histogram = new Recordable()

for (let i = 0; i < 600; i++)
  histogram.record(Math.round(Math.random() * 20) + 1)

histogram.plot()
24.33 ┤╭╮
23.27 ┤││
22.21 ┤││
21.15 ┤││
20.09 ┤││
19.03 ┤││
17.97 ┤││                                                                                                 ╭
16.91 ┤││                                                                                               ╭╮│
15.85 ┤││                    ╭╮                 ╭╮                      ╭╮             ╭╮               │││
14.79 ┤││ ╭╮ ╭╮   ╭╮         ││                 ││       ╭╮             ││╭╮           ││          ╭╮   │││
13.73 ┤││ ││ ││   ││         ││              ╭╮ ││╭╮     ││             ││││     ╭╮ ╭╮ ││      ╭╮  ││ ╭╮│╰╯
12.67 ┤│╰╮│╰─╯│  ╭╯│ ╭─╮ ╭─╮ │╰╮  ╭╮         ││ ││││╭─╮  │╰╮            ││││╭╮╭╮ ││ │╰╮│╰╮     ││ ╭╯│ │││
11.61 ┤│ ││   │ ╭╯ ╰╮│ ╰╮│ │ │ │  ││     ╭╮ ╭╯│ │││╰╯ │  │ │ ╭╮    ╭╮╭╮ │││││╰╯│╭╯│╭╯ ││ │  ╭╮ ││╭╯ ╰╮│││
10.55 ┤│ ││   ╰╮│   ││  ││ │╭╯ │╭╮││╭╮ ╭─╯│ │ ╰╮│││   ╰─╮│ │╭╯│    │││╰╮│││││  ││ ││  ╰╯ │  ││╭╯││   ╰╯││
9.48 ┤│ ╰╯    ││   ╰╯  ╰╯ ╰╯  ││││╰╯╰─╯  │ │  ││││     ││ ╰╯ ╰╮╭──╯╰╯ ││││╰╯  ╰╯ ││     │  │╰╯ ╰╯     ╰╯
8.42 ┤│       ╰╯              ╰╯╰╯       │ │  ││││     ╰╯     ││      ││││       ││     ╰─╮│
7.36 ┤│                                  ╰─╯  ╰╯╰╯            ╰╯      ╰╯││       ││       ││
6.30 ┤│                                                                 ╰╯       ╰╯       ╰╯
5.24 ┤│
4.18 ┤│
3.12 ┤│
2.06 ┤│
1.00 ┼╯
Nicholass-MacBook-Air:recordable nicholaswmin$

Tests

Install deps

npm ci

Run unit tests

npm test

Run test coverage

npm run test:coverage

Authors

License

MIT-0 "No Attribution" License

Releases

No releases published

Packages

No packages published