]> zoso.dev Git - nano-pow.git/commitdiff
Adjust truncated average calculation. Initialize benchmark min to max integer.
authorChris Duncan <chris@zoso.dev>
Thu, 23 Jan 2025 13:45:56 +0000 (05:45 -0800)
committerChris Duncan <chris@zoso.dev>
Thu, 23 Jan 2025 13:45:56 +0000 (05:45 -0800)
src/classes/gpu.ts
test.html

index bd5dcd11013a96cdb9ef739439aae2b147a8ca5a..5a3ba0418993f17cd0ad61cdccf782e7eed87bbd 100644 (file)
@@ -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)
                }
index 168cc998786d9df83f4720e62da24461186340c5..cec3854d018110d55ca601ddde9df945ae504204 100644 (file)
--- 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)
                                }