performancemeter

4.0.2 • Public • Published

Node.js Performance Meter

NPM version NPM downloads MIT License

A simple JavaScript performance meter.

const Meter = require('performancemeter');

// Optional
// Meter.name('Bla bla bla');

// NEW: restricts output data
// Meter.multiple();

// Optional, default: "medium" (other types: "veryeasy", "easy", "medium", "hard", "veryhard")
Meter.mode('easy');
// or sets 10 cycles, veryeasy === 100, easy = 100000, medium = 10000000, hard = 10000000000
Meter.mode(10);

// Meter.measure(TEST_NAME, function_test, [function_init]);
// @TEST_NAME {String}
// @function_test {Function}
// @function_init {Function} optional, can contains init values

// Example 1:
Meter.measure('String.indexOf()', 'str.indexOf("meter")', 'var str = "Performance meter"');
Meter.measure('RegExp.test()', 'reg.test(str)', 'var reg = /meter/; var str = "Performance meter');

// Example 2:
Meter.measure('String.indexOf()', () => str.indexOf('meter'), 'var str = "Performance meter"');
Meter.measure('RegExp.test()', () => reg.test(str), 'var reg = /meter/; var str = "Performance meter"');

// Example 3:
Meter.measure('String.indexOf()', function() {
	str.indexOf('meter');
}, function() {
	var str = 'Performance meter';
});

Meter.measure('RegExp.test()', function() {
	reg.test(str);
}, function() {
	var reg = /meter/;
	var str = 'Performance meter';
});

// Async example:
Meter.measure('nextTick', function() {
	process.nextTick(NEXT);
});

Meter.measure('immediate', function() {
	setImmediate(NEXT);
});

// NEW: With a custom counter
Meter.measure('nextTick', function() {
	COUNT++;
	process.nextTick(NEXT);
});

Meter.measure('immediate', function() {
	COUNT++;
	setImmediate(NEXT);
});

Contact

Readme

Keywords

Package Sidebar

Install

npm i performancemeter

Weekly Downloads

2

Version

4.0.2

License

MIT

Unpacked Size

12.2 kB

Total Files

4

Last publish

Collaborators

  • petersirka