UNPKG

300 BPlain TextView Raw
1export function timer() {
2 const start = process.hrtime()
3 return () => {
4 const [s, nanos] = process.hrtime(start)
5 const ms = nanos / 1000000
6
7 if (s < 1) {
8 return (ms >= 1 ? ms.toFixed(0) : ms.toFixed(2)) + 'ms'
9 } else {
10 return s + '.' + ms.toFixed(0) + 's'
11 }
12 }
13}