1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/lib/timer.js
Moritz Johner d0f57a68b2 feat: add db query latency metrics (#473)
* feat: add db metrics
Signed-off-by: Moritz Johner <beller.moritz@googlemail.com>

* fix: use base unit

Signed-off-by: Moritz Johner <beller.moritz@googlemail.com>
2020-02-20 08:34:27 +01:00

29 lines
727 B
JavaScript

'use strict';
const NS_TO_S = 1e9;
// seconds takes a tuple of [seconds, nanoseconds]
// and returns the time in seconds
const seconds = diff => diff[0] + diff[1] / NS_TO_S;
module.exports = {
// new returns a timer function. Call it to measure the time since the call to new().
// the timer function returns the duration in seconds
//
// usage:
//
// t = timer.new()
// setTimeout(() => {
// diff = t()
// console.log(diff) // 0.500003192s
// }, 500)
//
new: () => {
const now = process.hrtime();
// the timer function returns the time in seconds
// since new() was called
return () => seconds(process.hrtime(now));
},
seconds,
};