flaska/benchmark/utils.mjs

15 lines
383 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', 'μ', 'm', 'c', '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]
}
console.log(t, '=', Number((time / unitPower).toFixed(2)), unit)
}