1.0.6 • Published 3 years ago
towerman v1.0.6
Towerman
The library is a class with a constructor. The constructor accepts the unit of time (by default it is milliseconds). The methods can be used to track not only the running time of the entire program, but also of individual functions. Class have 3 main methods: globalSpyOn(), setSpyOnFunction(trackingFunction) and logElapsedTime(trackingFunction)
.
Installation
$ npm install --save-dev towerman
Usage
All program runtime (use globalSpyOn() method and logElapsedTime() method without argument):
// file.js
import TowermanAgent from 'towerman';
const agent = new TowermanAgent();
agent.globalSpyOn();
factorial(10);
// logElapsedTime without argument log all program runtime
agent.logElapsedTime();
// => file.js ------> <elapsed time> milliseconds
Functions runtime (use the setSpyOnFunction() method with the function you intend to track as an argument. Capture the execution time of the function using the logElapsedTime() method with the function to be tracked as an argument):
import TowermanAgent from 'towerman';
const agent = new TowermanAgent();
agent.setSpyOnFunction(factorial);
factorial(10);
agent.logElapsedTime(factorial);
// => factorial ------> <elapsed time> milliseconds
Use seconds:
// file.js
import TowermanAgent from 'towerman';
const agent = new TowermanAgent('seconds');
agent.globalSpyOn();
factorial(10);
agent.logElapsedTime();
// => file.js ------> <elapsed time> seconds