1 | # nanotiming [![stability][0]][1]
|
2 | [![npm version][2]][3] [![build status][4]][5]
|
3 | [![downloads][8]][9] [![js-standard-style][10]][11]
|
4 |
|
5 | Small timing library. Useful to integrate into libraries that have multiple
|
6 | methods. Only works in the browser, does nothing in Node.
|
7 |
|
8 | ## Usage
|
9 | ```js
|
10 | var nanotiming = require('nanotiming')
|
11 |
|
12 | var loopTiming = nanotiming('my-timing.my-loop')
|
13 | var i = 1000
|
14 | while (--i) console.log(i)
|
15 | loopTiming()
|
16 |
|
17 | // Inspect timings when we have spare time available
|
18 | window.requestIdleCallback(function () {
|
19 | var timings = window.performance.getEntries()
|
20 | var timing = timings[timings.length - 1]
|
21 | console.log(timing.name, timing.duration) // log the last entry
|
22 | performance.clearMeasures(timing.name) // be a good citizen and free after use
|
23 | })
|
24 | ```
|
25 |
|
26 | ## Timing names
|
27 | Timings inside the view are appended with a unique UUID so they can be cleared
|
28 | individually. While there's no strict format for timing formats, we recommend
|
29 | using a format along these lines:
|
30 | ```txt
|
31 | choo.render [12356778]
|
32 | choo.route('/') [13355671]
|
33 | choo.emit('log:debug') [13355675]
|
34 | ```
|
35 |
|
36 | ## API
|
37 | ### `endTiming = nanotiming(name)`
|
38 | Start a new timing.
|
39 |
|
40 | ### `endTiming()`
|
41 | Close the timing. Measuring the timing is done inside a `requestIdleCallback()`
|
42 | tick, so it might not be available immediately.
|
43 |
|
44 | ## License
|
45 | [MIT](https://tldrlegal.com/license/mit-license)
|
46 |
|
47 | [0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square
|
48 | [1]: https://nodejs.org/api/documentation.html#documentation_stability_index
|
49 | [2]: https://img.shields.io/npm/v/nanotiming.svg?style=flat-square
|
50 | [3]: https://npmjs.org/package/nanotiming
|
51 | [4]: https://img.shields.io/travis/yoshuawuyts/nanotiming/master.svg?style=flat-square
|
52 | [5]: https://travis-ci.org/yoshuawuyts/nanotiming
|
53 | [6]: https://img.shields.io/codecov/c/github/yoshuawuyts/nanotiming/master.svg?style=flat-square
|
54 | [7]: https://codecov.io/github/yoshuawuyts/nanotiming
|
55 | [8]: http://img.shields.io/npm/dm/nanotiming.svg?style=flat-square
|
56 | [9]: https://npmjs.org/package/nanotiming
|
57 | [10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
|
58 | [11]: https://github.com/feross/standard
|