Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryardley/console-timer
A better timer for the console.
https://github.com/ryardley/console-timer
Last synced: 10 days ago
JSON representation
A better timer for the console.
- Host: GitHub
- URL: https://github.com/ryardley/console-timer
- Owner: ryardley
- Created: 2016-10-06T23:54:11.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-13T02:49:59.000Z (about 8 years ago)
- Last Synced: 2024-10-26T06:52:34.609Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Console Timer
### A better timer for the console.
I wanted a simple referential timer that I could use that works the same way in all systems. The native console timer functions can be buggy in Chrome and other systems don't even all support it such as older versions of iOS.
However it is useful to have a timer on the global `console` object and not have to require it into your environment when testing performance.
## Usage
```javascript
import consoleTimer from 'console-timer';
consoleTimer();console.time('foo');
somethingExpensive();
console.timeEnd('foo'); // foo(203ms)
```## Bound finish function
```javascript
import consoleTimer from 'console-timer';
consoleTimer();const finish = console.time.bound('foo');
somethingExpensive();
finish(); // foo(203ms)
```## Name collisions
You can pass in a method map to override the method names if you are worried about collision.```javascript
import consoleTimer from 'console-timer';
consoleTimer({
methods: {
time: 't',
timeEnd: 'te'
}
});console.t('foo');
somethingExpensive();
console.te('foo'); // foo(203ms)
```## Customize your colors
You can pass a colors object to the options when setting up console-timer for multicoloured ANSI terminals
```javascript
consoleTimer({
colors: {
name: 'cyan',
time: 'yellow',
msg: 'red',
}
});
```
## Use objects as referencesYou can use (mutable) objects as timer keys.
```javascript
console.time(MyComponent);
somethingExpensive();
console.timeEnd(MyComponent); // foo(203ms)
```## Don't use console if you don't want to
You can use another context if you don't want monkey patched methods on console
```javascript
import consoleTimer from 'console-timer';let myobj = {};
consoleTimer({context: myobj});
myobj.time('foo');
somethingExpensive();
myobj.timeEnd('foo'); // foo(203ms)
```## Multiple starts
Starting a timer multiple times will simply interrupt timer and restart
```javascript
import consoleTimer from 'console-timer';
consoleTimer();console.time('foo');
console.time('foo'); // foo(0ms) - INTERRUPTED!
somethingExpensive();
console.timeEnd('foo'); // foo(203ms)
```