elapsed-time-util
Version:
TypeScript script to find and keep track of elapsed time of different code blocks
87 lines (59 loc) • 3.09 kB
Markdown
TypeScript script to find and keep track of elapsed time of different code blocks
[](https://badge.fury.io/js/elapsed-time-util)
[](https://www.npmjs.com/package/elapsed-time-util)
[](https://opensource.org/licenses/MIT)
```
$ npm install --save elapsed-time-util
```
```js
import { startEvent, endEvent } from 'elapsed-time-util';
startEvent('myEvent');
// do something
const elapsed = endEvent('myEvent');
console.log(`myEvent took ${elapsed}ms`); // myEvent took 100ms
```
Starts an event timer and returns the start time. All events are logged in a global object.
Starts an event timer and returns the start time without logging the entry to the global object.
Ends an event timer and returns the elapsed time. All events are logged in a global object.
Ends an event timer and returns the elapsed time without logging the entry to the global object.
Returns the event entry from the global object. If the event does not exist, throws an error.
Returns the start time of the event from the global object. If the event does not exist, throws an error.
Returns the end time of the event from the global object. If the event does not exist, throws an error. If the event has not ended, returns `undefined`.
Returns the elapsed time of the event from the global object. If the event does not exist, throws an error. If the event has not ended, returns the elapsed time up to the current time.
Returns the elapsed time of the event from the global object in seconds. If the event does not exist, throws an error. If the event has not ended, returns the elapsed time up to the current time.
Returns the elapsed time of the event from the global object in minutes. If the event does not exist, throws an error. If the event has not ended, returns the elapsed time up to the current time.
Clears all events from the global object.
Clears the event from the global object. If the event does not exist, throws an error.
Returns all events from the global object.
Prints a table of all events from the global object using `console.table`.
Prints a table of the event from the global object using `console.table`. If the event does not exist, throws an error.
The event object is a simple object with the following properties:
```js
[]: {
startTime: number,
endTime: number | null,
elapsed: number | null
}
```
MIT ©