https://github.com/bufferapp/buffer-js-chronos
A small library to handle browsers timing api
https://github.com/bufferapp/buffer-js-chronos
Last synced: 4 months ago
JSON representation
A small library to handle browsers timing api
- Host: GitHub
- URL: https://github.com/bufferapp/buffer-js-chronos
- Owner: bufferapp
- License: mit
- Created: 2017-01-06T11:39:14.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-19T00:22:20.000Z (almost 9 years ago)
- Last Synced: 2025-01-30T23:46:54.382Z (over 1 year ago)
- Language: JavaScript
- Size: 31.3 KB
- Stars: 0
- Watchers: 8
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chronos
A small library to handle browser timining measures
## How To
install it
```
npm i --save @bufferapp/chronos
import chronos from '@bufferapp/chronos';
const ch = chronos();
```
The simplest way to measure something is to start the measure with `ch.startMeasure('bar')` and then stop it `ch.stopMeasure('bar')`.
To store the measure you should define a storing method when you instatiate Chronos passing it down in the configuration options
```
const ch = chronos({
store: (data) => {
…
}
})
```
When that is provided Chronos will auto save the measures for you.
Chronos is using `requestIdleCallback` to parse and store measures, so autosave won't effect your app performances, anyway you are free to disable this behaviour setting `autoSave: false` in the options.
In this case you can manually save measures with `ch.saveToStore()`.
You can measure anything against browser timing event with `ch.measureFromSpecialEvent({ name: 'foo', eventName: 'navigationStart' })`, there is also a convenient method to measure against Navigation Start `ch.measureFromNavigationStart('foo')`.
If you want to store any extra data along with your measures you can pass a `data` object in measure start options `ch.startMeasure({name: 'foo', data: {tags: ['foo', 'bar']}})`, the data field will be passed down to your store method.
Happy measuring!