mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
d0f57a68b2
* 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>
29 lines
727 B
JavaScript
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,
|
|
};
|