}
export function average (times) {
- let sum = 0, reciprocals = 0, product = 1, count = times.length, min = 0xffff, max = 0
+ let sum = 0, reciprocals = 0, logarithms = 0, count = times.length, min = 0xffff, max = 0
for (let i = 0; i < count; i++) {
sum += times[i]
reciprocals += 1 / times[i]
- product *= times[i]
+ logarithms += Math.log(times[i])
min = Math.min(min, times[i])
max = Math.max(max, times[i])
}
total: sum,
arithmetic: sum / count,
harmonic: count / reciprocals,
- geometric: Math.pow(product, 1 / count),
+ geometric: Math.exp(logarithms / count),
min: min,
max: max
}