performance-nodejs
Advanced tools
Comparing version
{ | ||
"extends": "airbnb/base" | ||
"extends": "airbnb/base", | ||
"rules": { | ||
"strict": 0 | ||
} | ||
} |
45
index.js
'use strict'; | ||
/* eslint import/no-unresolved: 0 */ | ||
const v8 = require('v8'); | ||
const noop = function() {}; | ||
module.exports = performance; | ||
const util = require('util'); | ||
function noop() {} | ||
function performance(fn, interval) { | ||
interval = interval || 100; | ||
fn = fn || noop; | ||
function getDelay(start, interval) { | ||
const delta = process.hrtime(start); | ||
const nanosec = delta[0] * 1e9 + delta[1]; | ||
return (nanosec / 1e6 | 0) - interval; | ||
} | ||
function getHeapStatistics() { | ||
return v8.getHeapStatistics(); | ||
} | ||
function get(arr, filter, defaultValue) { | ||
let result; | ||
arr.forEach(tmp => { | ||
if (tmp && filter(tmp)) { | ||
result = tmp; | ||
} | ||
}); | ||
return result || defaultValue; | ||
} | ||
function performance() { | ||
/* eslint prefer-rest-params: 0 */ | ||
const args = Array.from(arguments); | ||
const interval = get(args, util.isNumber, 100); | ||
const fn = get(args, util.isFunction, noop); | ||
let start = process.hrtime(); | ||
@@ -13,3 +36,3 @@ return setInterval(() => { | ||
lag: getDelay(start, interval), | ||
heap: getHeapStatistics() | ||
heap: getHeapStatistics(), | ||
}); | ||
@@ -21,10 +44,2 @@ start = process.hrtime(); | ||
function getDelay(start, interval) { | ||
const delta = process.hrtime(start); | ||
const nanosec = delta[0] * 1e9 + delta[1]; | ||
return (nanosec / 1e6 | 0) - interval; | ||
} | ||
function getHeapStatistics() { | ||
return v8.getHeapStatistics(); | ||
} | ||
module.exports = performance; |
{ | ||
"name": "performance-nodejs", | ||
"description": "get nodejs performance, eg: heap statistics, event loop delay", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"author": "Tree Xie <vicansocanbico@gmail.com>", | ||
@@ -13,3 +13,3 @@ "keywords": [ | ||
"scripts": { | ||
"test": "node ./node_modules/.bin/eslint ./lib/*.js && node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha ./test/*.js --" | ||
"test": "node ./node_modules/.bin/eslint ./index.js && node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha ./test/*.js --" | ||
}, | ||
@@ -23,7 +23,8 @@ "repository": { | ||
}, | ||
"readme": "Get nodejs performance, eg: heap statistics, event loop delay", | ||
"readmeFilename": "Readme.md", | ||
"devDependencies": { | ||
"eslint": "^2.5.1", | ||
"eslint-config-airbnb": "^6.2.0", | ||
"istanbul": "^0.4.2", | ||
"eslint": "^2.9.0", | ||
"eslint-config-airbnb": "^8.0.0", | ||
"eslint-plugin-import": "^1.6.1", | ||
"istanbul": "^0.4.3", | ||
"mocha": "^2.4.5" | ||
@@ -30,0 +31,0 @@ }, |
# performance-nodejs | ||
[](https://travis-ci.org/vicanso/performance-nodejs) | ||
[](https://travis-ci.org/vicanso/performance-nodejs) | ||
[](https://coveralls.io/r/vicanso/performance-nodejs?branch=master) | ||
[](https://www.npmjs.org/package/performance-nodejs) | ||
[](https://github.com/vicanso/performance-nodejs) | ||
Get nodejs performance, eg: heap statistics, event loop delay | ||
@@ -6,0 +10,0 @@ |
Sorry, the diff of this file is not supported yet
3357
33.69%42
61.54%42
10.53%5
25%