time-me / 1.2.0 last updated a month ago created on Mar 16th 2015
Install
npm install --save time-me
Clone
git clone git@github.com:benbria/time-me.git
dependencies
| main |
|
fn-intercept | 1.0.0 | MIT |
|
|
hrstopwatch | 1.0.0 | MIT | |
|
|
timeunit | 1.1.1 | Public Domain |
maintainers
versions
| 1.2.0 | a month ago | calvinwiebe |
| 1.1.1 | 9 months ago | calvinwiebe |
| 1.0.1 | a year ago | calvinwiebe |
| 1.0.0 | a year ago | calvinwiebe |
readme
timeMe!
Time a block of code with minimal effort.
Sometimes you want to time a certain execution path to see its performance. So, you
add a bunch of time captures and log statements. Cleaning them up isn't so much fun.
It would also be nice to leave them in your code so they can be enabled at will. timeMe
is meant to help in that situation.
timeMe Will take some options and a function to wrap. It will return the wrapped function. Everytime that function is executed, its time will be recorded. You can choose
to print it out, or query the function for its lastTime.
In the case of Promise based functions, timeMe will wait until the Promise resolves, log the time it took to resolve, and then pass the promise back.
Usage
Methods
timeMe.configure
Globally configure the module on what log function to use. Defaults to
console.log
The configured logging function will be passed two arguments:
- A string containing the message used to name the call, and the call time.
An object containing the same information, of the form
timeMe.async
timeMe.sync
timeMe.promise
All three methods can be called like so
Options
options.msg
The prefix of the logged time
options.index
(only for timeMe.async) You can specify the index of the callback in the wrapped
function. Defaults to the last argument.
options.noLog
Turn logs on or off. Defaults to false (meaning logging on).
wrappedFn.lastTime
Whenever a wrapped function is called, additionally to logging the time, a property will
be set on the function: lastTime. You can query the function for the property.