measure-it
v1.0.1
Published
Measure performance of code blocks
Downloads
1
Maintainers
Readme
measure-it
Measure performance of code blocks
Install
npm install measure-it --save
Usage
Measure One
const measureOf = require('measure-it');
let measure = measureOf('Awesome Code').start();
awesomeCode();
console.log(measure.get());
// 10
console.log(measure.serialize());
// <Awesome Code> 10
Measure Multiple Groups
const measureOf = require('measure-it');
let measure = measureOf('Awesome Code');
measure.start('block 1');
awesomeCode();
measure.stop('block 1').start('block 2');
awesomeCode();
measure.stop('block 2');
console.log(measure.get('block 1'));
// 11
console.log(measure.get('block 2'));
// 12
console.log(measure.serialize());
// <Awesome Code> block 1: 11, block 2: 12
Measure Asynchronous Code Blocks
const measureOf = require('measure-it');
let measure = measureOf('Awesome Code');
measure.start('block 1');
setTimeout(() => {
measure.stop('block 1').start('block 2');
console.log(measure.get('block 1'));
// 1000
setTimeout(() => {
measure.stop('block 2');
console.log(measure.get('block 2'));
// 1000
console.log(measure.serialize());
// <Awesome Code> block 1: 1000, block 2: 1000
}, 1000);
}, 1000);
Start / Stop Multiple Groups At Once
const measureOf = require('measure-it');
let measure = measureOf('Awesome Code').start('block 1', 'block 2', 'block 3');
awesomeCode();
measure.stop('block 1');
awesomeCode();
measure.stop('block 2', 'block 3');
console.log(measure.get('block 1'));
// 10
console.log(measure.get('block 2'));
// 20
console.log(measure.get('block 3'));
// 20
console.log(measure.serialize());
// <Awesome Code> block 1: 10, block 2: 20, block 3: 20
Measure Progression
const measureOf = require('measure-it');
let measure = measureOf('Awesome Code').start();
awesomeCode();
measure.stop();
awesomeCode();
measure.stop();
console.log(measure.get());
// [10, 20]
console.log(measure.serialize());
// <Awesome Code> 10, 20