flaska/benchmark/utils.mjs
2024-11-18 03:57:51 +00:00

15 lines
384 B
JavaScript

export function printTime (t) {
let time = Number(t)
let units = ['n', 'μ', 'ms', 's']
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
unit = units[i + 1]
}
console.log(t, '=', Number((time / unitPower).toFixed(2)), unit)
}