From 7d6d9feb134ba5a5341537c5cb53c7a48ac5c582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 10 Oct 2024 12:12:15 +0200 Subject: [PATCH] fix: handle divide by zero in throughput samples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/lib.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.js b/src/lib.js index f1c4995..2a80861 100644 --- a/src/lib.js +++ b/src/lib.js @@ -287,7 +287,9 @@ const buildMeasurementStats = latencySamples => { const latencyRmoe = (latencyMoe / checkDividend(latencyAvg)) * 100 // Throughput - const throughputSamples = latencySamples.map(sample => 1e9 / sample) + const throughputSamples = latencySamples.map( + sample => (sample !== 0 ? 1e9 / sample : 1e9 / latencyAvg) // Use latency average as imputed sample + ) throughputSamples.sort((a, b) => a - b) const throughputAvg = average(throughputSamples) const throughputVr = variance(throughputSamples, throughputAvg)