- install our Node.js module Performance Meter
$ npm install performancemeter
- and create custom tests
Running tests
- save each test into separate file
- run
$ node testname.js
Caching objects
const Meter = require('performancemeter');
Meter.measure('Uncached', function() {
fn({ success: true });
}, function() {
function fn(obj){obj.success;}
});
Meter.measure('Cached', function() {
fn(success);
}, function() {
var success = { success: true };
function fn(obj){obj.success;}
});
Caching object with assignment
const Meter = require('performancemeter');
Meter.measure('Uncached', function() {
fn({ success: INDEX % 2 === 0 });
}, function() {
function fn(obj){obj.success;}
});
Meter.measure('Cached with assignment', function() {
success.success = INDEX % 2 === 0;
fn(success);
}, function() {
var success = { success: true };
function fn(obj){obj.success;}
});
Delete vs Undefined
const Meter = require('performancemeter');
Meter.measure('delete', function() {
var obj = { success: true };
delete obj.success;
JSON.stringify(obj);
});
Meter.measure('undefined', function() {
var obj = { success: true };
obj.success = undefined;
JSON.stringify(obj);
});
Meter.mode('low');
Caching DateTime
const Meter = require('performancemeter');
Meter.measure('Uncached', function() {
fn(new Date());
}, function() {
function fn(dt) {dt;}
});
Meter.measure('Cached', function() {
fn(current);
}, function() {
var current = new Date();
function fn(dt) {dt;}
});
Meter.measure('Partially cached', function() {
if (INDEX % 5 === 0)
current = new Date();
fn(current);
}, function() {
var current = new Date();
function fn(dt) {dt;}
});