Debog
A simple TypeScript decorator to add performance timing to your class methods.
Installation
$ yarn add debog
Requirements
This library uses TypeScript decorators. Ensure experimentalDecorators
is enabled in your tsconfig.json
file.
Usage
Import debog
into a TypeScript file and append your classes with the decorator. Pass the names of any methods you want to profile.
debog
automatically waits for async methods to resolve before timing!
example.shortMethod // logs "shortMethod took 0ms"example.longMethod // logs "longMethod took 3ms"example.asyncMethod // logs "asyncMethod took 1000ms"
You can alternatively restrict output until a certain threshold is reached. For example, to log when a method takes longer than 5ms:
await example.waitMethod // logs "waitMethod took 10ms"example.instantMethod // logs nothing
Output
You are not restricted to using console.log
as output. In fact, you can
output any timing call to any destination you want such as statsd, prometheus,
etc.
Simply override the exposed logger
attribute.
debog.logger =
API
This library exports one default decorator function, defined as:
License
MIT