https://github.com/fedebertolini/fn-exec-stats
Get execution stats for javascript functions
https://github.com/fedebertolini/fn-exec-stats
Last synced: 24 days ago
JSON representation
Get execution stats for javascript functions
- Host: GitHub
- URL: https://github.com/fedebertolini/fn-exec-stats
- Owner: fedebertolini
- License: mit
- Created: 2018-07-30T22:39:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-31T08:56:54.000Z (almost 8 years ago)
- Last Synced: 2025-02-11T11:55:37.530Z (over 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fn-exec-stats
Get execution stats for javascript functions. This is only intended to debug performance issues, DO NOT USE IN PRODUCTION!
## Install
`npm install fn-exec-stats` or `yarn add fn-exec-stats`
## Usage
```js
const fnWrapper = require('fn-exec-stats'); // or `import fnWrapper from 'fn-exec-stats';`
const wrappedFunction = fnWrapper(Math.random, {
enabled: false, // defaults to true
});
wrappedFunction.enableExecStats(); // start tracking the executions
// get some random numbers
wrappedFunction();
wrappedFunction();
wrappedFunction();
// log the executions stats
const stats = wrappedFunction.getExecStats();
console.log(stats);
// prints the stats in milliseconds:
// {
// "executedTimes": 3,
// "maxTime": 3,
// "meanTime": 2,
// "minTime": 1,
// "totalTime": 6
// }
wrappedFunction.disableExecStats(); // stops tracking the executions
// After disabling the tracking, calling `getExecStats` will return the last stats
// before the tracking was disabled
```