2024-11-02 12:44:54 +00:00
|
|
|
export function printTime (t) {
|
|
|
|
let time = Number(t)
|
2024-11-18 03:57:51 +00:00
|
|
|
let units = ['n', 'μ', 'ms', 's']
|
2024-11-02 12:44:54 +00:00
|
|
|
let unit = units[0]
|
|
|
|
let unitPower = 1
|
|
|
|
for (let i = 0; i < units.length; i++) {
|
|
|
|
let power = Math.pow(10, (i + 1) * 3)
|
|
|
|
if (power * 2 > time) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
unitPower = power
|
2024-11-18 03:57:51 +00:00
|
|
|
unit = units[i + 1]
|
2024-11-02 12:44:54 +00:00
|
|
|
}
|
|
|
|
console.log(t, '=', Number((time / unitPower).toFixed(2)), unit)
|
2024-11-18 03:57:51 +00:00
|
|
|
}
|