Server-Timing HTTP header helper
Create timers and report to the browser with a Server-Timing
header.
header-timers
on npmjs.org »
Contents:
Install
•
Usage
•
Goals
•
Server-Timing
Reference
Install
npm i header-timers
[!NOTE]
This is a Node.js library and won't work in a browser runtime.
Usage
Just .js samples for now:
import HeaderTimers from 'header-timers'
const timers = HeaderTimers()
const { start, stop } = timers
start('open')
stop('open')
start('database', 'collecting data')
start('analytics', 'log request data')
await new Promise(resolve => setTimeout(resolve, 100))
stop('analytics')
await new Promise(resolve => setTimeout(resolve, 500))
stop('database')
console.log('TIMER COUNT', timers.timers().length)
console.log(timers.key)
console.log(timers.timers())
console.log(timers.values())
console.log(timers.value())
console.log(timers.string())
console.log(timers.object())
Also...
start("this won't work")
timers.reset()
stop("this won't work")
console.log('TIMER COUNT', timers.timers().length)
start('reset')
await new Promise(resolve => setTimeout(resolve, 100))
stop('reset')
console.log('TIMER COUNT', timers.timers().length)
console.log('NEW Header String', timers.string())
And...
start()
stop()
start()
start('foo')
start()
stop()
await new Promise(resolve => setTimeout(resolve, 100))
stop()
stop('foo')
Goals
Be helpful and accurate. Stay small and fast. Then be intuitive. This means:
- zero dependencies
- measure in nanoseconds
- option to disable
- fast primitives/operations (this needs review)
- terse but readable API
"It's just strings all the way down"