mirror of https://github.com/iptv-org/iptv
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
579 B
JavaScript
30 lines
579 B
JavaScript
3 years ago
|
const { performance } = require('perf_hooks')
|
||
|
const dayjs = require('dayjs')
|
||
|
const duration = require('dayjs/plugin/duration')
|
||
|
const relativeTime = require('dayjs/plugin/relativeTime')
|
||
|
|
||
|
dayjs.extend(relativeTime)
|
||
|
dayjs.extend(duration)
|
||
|
|
||
|
const timer = {}
|
||
|
|
||
|
let t0 = 0
|
||
|
|
||
|
timer.start = function () {
|
||
|
t0 = performance.now()
|
||
|
}
|
||
|
|
||
|
timer.format = function (f) {
|
||
|
let t1 = performance.now()
|
||
|
|
||
|
return dayjs.duration(t1 - t0).format(f)
|
||
|
}
|
||
|
|
||
|
timer.humanize = function (suffix = true) {
|
||
|
let t1 = performance.now()
|
||
|
|
||
|
return dayjs.duration(t1 - t0).humanize(suffix)
|
||
|
}
|
||
|
|
||
|
module.exports = timer
|