@patuach/oh-my-gauge

1.0.1 • Public • Published

Oh My Gauge!

Gauge - time Javascript operations

npm package Codeship Status

pull requests issues

Install

npm i @patuach/oh-my-gauge
const {Gauge, Benchmark} = require('@patuach/oh-my-gauge');

Usage

Gauge

const Gauge = require('@patuach/oh-my-gauge').Gauge;
const gauge = new Gauge((res, name) => console.log(`${name} took ${res}ms`));
//                        ^     ^         ^
//              Milliseconds  String   report-method

const myObj = {
    name: 'My Obj',
    sayName: function() {
        return this.name;
    }
};

myObj.sayName = gauge(myObj.sayName, 'sayName method');

Benchmark

const Benchmark = require('@patuach/oh-my-gauge').Benchmark;
const benchmark = new Benchmark();

benchmark(
  100000,
  [() => {/* Do thing one   */}, 'Thing 1 description'],
  [() => {/* Do thing two   */}, 'Thing 2 description'],
  [() => {/* Do thing three */}, 'Thing 3 description']
);

Or use a map

const Benchmark = require('@patuach/oh-my-gauge/lib/benchmark'); // Require to the module directly
const benchmark = new Benchmark(
    console.warn, // override the default console.log callback
    (ms, name) => `Method: ${name}, Time: ${ms}` // override default formatter
);

const things = new Map();
things.set(() => {/* Do thing one   */}, 'Thing 1 description');
things.set(() => {/* Do thing two   */}, 'Thing 2 description');
things.set(() => {/* Do thing three */}, 'Thing 3 description');

benchmark(1e5, things);

Readme

Keywords

none

Package Sidebar

Install

npm i @patuach/oh-my-gauge

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • yossi-eynav
  • omrilotan