timer-decorator
v0.0.4
Published
ES7 promise-aware timer decorator
Downloads
4
Maintainers
Readme
Timer Decorator
A simple Promise-aware ES7 timer decorator. Just logs the processing time for the given function, or the time until the promise resolves (ignores rejected promises). Note that the promise itself adds ~35-40ms in my basic testing.
Installation
npm install --save-dev timer-decorator
Usage
import timer from 'timer-decorator';
class Foo {
@timer
myMethod() {
// ...
}
}
will log something like:
Foo[0].myMethod: 123.456ms
The [0]
is the instance #.
Enable and Disable
To enable or disable the timer, call:
timer.enable(this);
timer.disable(this);
where this
is the class instance.
Release
timer.release(this);
to release the object and allow for gc to clean it. Note that you probably
shouldn't be using this in production anyway, so it's somewhat irrelevant if
you don't do this (I'm just writing it for you to be aware that you will
keep around every object that has a timer in memory, forever, if release
isn't called).