From 260012b95fbfe95a6647cef4aa8faefe1d17a918 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 23 Jan 2025 05:45:56 -0800 Subject: [PATCH] Adjust truncated average calculation. Initialize benchmark min to max integer. --- src/classes/gpu.ts | 11 +++++++---- test.html | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/classes/gpu.ts b/src/classes/gpu.ts index bd5dcd1..5a3ba04 100644 --- a/src/classes/gpu.ts +++ b/src/classes/gpu.ts @@ -105,7 +105,7 @@ export class NanoPowGpu { } static #logAverages (times: number[]): void { - let count = times.length, sum = 0, reciprocals = 0, logarithms = 0, truncated = 0, min = 0xffff, max = 0, rate = 0 + let count = times.length, truncatedCount = 0, truncated = 0, sum = 0, reciprocals = 0, logarithms = 0, min = Number.MAX_SAFE_INTEGER, max = 0, rate = 0 times.sort() for (let i = 0; i < count; i++) { sum += times[i] @@ -113,16 +113,19 @@ export class NanoPowGpu { logarithms += Math.log(times[i]) min = Math.min(min, times[i]) max = Math.max(max, times[i]) - if (count < 3 || (i > (count * 0.1) && i < (count * 0.9))) truncated += times[i] + if (count < 3 || (i > (0.1 * count) && i < (0.9 * (count - 1)))) { + truncated += times[i] + truncatedCount++ + } } const averages = { "Count (dispatches)": count, "Total (ms)": sum, - "Rate (d/s)": 1000 * count * 0.8 / (truncated || sum), + "Rate (d/s)": 1000 * truncatedCount / (truncated || sum), "Minimum (ms)": min, "Maximum (ms)": max, "Arithmetic Mean (ms)": sum / count, - "Truncated Mean (ms)": truncated / (count * 0.8), + "Truncated Mean (ms)": truncated / truncatedCount, "Harmonic Mean (ms)": count / reciprocals, "Geometric Mean (ms)": Math.exp(logarithms / count) } diff --git a/test.html b/test.html index 168cc99..cec3854 100644 --- a/test.html +++ b/test.html @@ -29,7 +29,7 @@ SPDX-License-Identifier: GPL-3.0-or-later } function average (times, type, effort) { - let count = times.length, sum = 0, reciprocals = 0, logarithms = 0, truncated = 0, min = 0xffff, max = 0, rate = 0 + let count = times.length, truncatedCount = 0, sum = 0, truncated = 0, reciprocals = 0, logarithms = 0, min = Number.MAX_SAFE_INTEGER, max = 0, rate = 0 times.sort() for (let i = 0; i < count; i++) { sum += times[i] @@ -37,18 +37,21 @@ SPDX-License-Identifier: GPL-3.0-or-later logarithms += Math.log(times[i]) min = Math.min(min, times[i]) max = Math.max(max, times[i]) - if (count < 3 || (i > (count * 0.1) && i < (count * 0.9))) truncated += times[i] + if (count < 3 || (i > (0.1 * count) && i < (0.9 * (count - 1)))) { + truncated += times[i] + truncatedCount++ + } } const title = `NanoPow (${type}) | Effort: ${effort} | Dispatch: ${(0x100 * effort) ** 2} | Threads: ${8 * 8 * (0x100 * effort) ** 2}` return { [title]: { count: count, total: sum, - rate: 1000 * count * 0.8 / (truncated || sum), + rate: 1000 * truncatedCount / (truncated || sum), min: min, max: max, arithmetic: sum / count, - truncated: truncated / (count * 0.8), + truncated: truncated / truncatedCount, harmonic: count / reciprocals, geometric: Math.exp(logarithms / count) } -- 2.34.1