flaska/benchmark/utils.mjs

16 lines
384 B
JavaScript
Raw Permalink Normal View History

2024-11-02 12:44:54 +00:00
export function printTime (t) {
let time = Number(t)
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
unit = units[i + 1]
2024-11-02 12:44:54 +00:00
}
console.log(t, '=', Number((time / unitPower).toFixed(2)), unit)
}