From 3a9f90253bde1094634078bafc40446b7db3f080 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 6 Jan 2025 11:24:02 -0800 Subject: [PATCH] Benchmark min and max times, and add another round of testing. --- GLOBALS.mjs | 12 ++++++++---- benchmarks.md | 7 +++++++ perf/block.perf.js | 12 +++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/GLOBALS.mjs b/GLOBALS.mjs index 0b02fc9..c6fab27 100644 --- a/GLOBALS.mjs +++ b/GLOBALS.mjs @@ -17,17 +17,21 @@ if (globalThis.sessionStorage == null) { } export function average (times) { - let sum = 0, reciprocals = 0, product = 1, count = times.length + let sum = 0, reciprocals = 0, product = 1, count = times.length, min = 0xffff, max = 0 for (let i = 0; i < count; i++) { sum += times[i] reciprocals += 1 / times[i] product *= times[i] + min = Math.min(min, times[i]) + max = Math.max(max, times[i]) } return { total: sum, arithmetic: sum / count, harmonic: count / reciprocals, - geometric: Math.pow(product, 1 / count) + geometric: Math.pow(product, 1 / count), + min: min, + max: max } } @@ -57,7 +61,7 @@ await suite('TEST RUNNER CHECK', async () => { console.assert(failures.some(call => /.*promise should fail.*/.test(call[0])) === true, `bad promise not errored`) console.assert(passes.some(call => /.*promise should fail.*/.test(call[0])) === false, 'bad promise logged') - await test('async should pass', async () => { }) + await test('async should pass', async () => {}) console.assert(failures.some(call => /.*async should pass.*/.test(call[0])) === false, 'good async errored') console.assert(passes.some(call => /.*async should pass.*/.test(call[0])) === true, 'good async not logged') @@ -65,7 +69,7 @@ await suite('TEST RUNNER CHECK', async () => { console.assert(failures.some(call => /.*async should fail.*/.test(call[0])) === true, 'bad async not errored') console.assert(passes.some(call => /.*async should fail.*/.test(call[0])) === false, 'bad async logged') - await test('function should pass', () => { }) + await test('function should pass', () => {}) console.assert(failures.some(call => /.*function should pass.*/.test(call[0])) === false, 'good function errored') console.assert(passes.some(call => /.*function should pass.*/.test(call[0])) === true, 'good function not logged') diff --git a/benchmarks.md b/benchmarks.md index 30d20bd..7407db4 100644 --- a/benchmarks.md +++ b/benchmarks.md @@ -29,6 +29,7 @@ Geometric: Infinity ms block.perf.js:59:10 PASS Customized PoW: Time to calculate proof-of-work for a send block 512 times +/media/plex/Shows/STAR_TREK_DISCOVERY_S1_D1/STAR_TREK_DISCOVERY (Season 1 Disc 1) CHROMIUM with more accurate timings @@ -37,3 +38,9 @@ Average: 366.07109375001164 ms Harmonic: 220.70399520519166 ms Geometric: Infinity ms Customized PoW: Time to calculate proof-of-work for a send block 512 times + +Total: 187827.7999998629 ms +block.perf.js:57 Average: 366.85117187473224 ms +block.perf.js:58 Harmonic: 223.9897252426498 ms +block.perf.js:59 Geometric: Infinity ms +GLOBALS.mjs:42 PASS Customized PoW: Time to calculate proof-of-work for a send block 512 times diff --git a/perf/block.perf.js b/perf/block.perf.js index 555eac6..e2deeb7 100644 --- a/perf/block.perf.js +++ b/perf/block.perf.js @@ -28,11 +28,13 @@ await suite('Block performance', async () => { times.push(end - start) console.log(`${work} (${end - start} ms) ${hashes[i]}`) } - const { total, arithmetic, harmonic, geometric } = average(times) + const { total, arithmetic, harmonic, geometric, min, max } = average(times) console.log(`Total: ${total} ms`) console.log(`Average: ${arithmetic} ms`) console.log(`Harmonic: ${harmonic} ms`) console.log(`Geometric: ${geometric} ms`) + console.log(`Minimum: ${min} ms`) + console.log(`Maximum: ${max} ms`) }) await test(`Customized PoW: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => { @@ -52,11 +54,13 @@ await suite('Block performance', async () => { times.push(end - start) console.log(`${block.work} (${end - start} ms)`) } - const { total, arithmetic, harmonic, geometric } = average(times) + const { total, arithmetic, harmonic, geometric, min, max } = average(times) console.log(`Total: ${total} ms`) console.log(`Average: ${arithmetic} ms`) console.log(`Harmonic: ${harmonic} ms`) console.log(`Geometric: ${geometric} ms`) + console.log(`Minimum: ${min} ms`) + console.log(`Maximum: ${max} ms`) }) await skip(`Original PoW module: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => { @@ -71,10 +75,12 @@ await suite('Block performance', async () => { times.push(end - start) console.log(`${work} (${end - start} ms)`) } - const { total, arithmetic, harmonic, geometric } = average(times) + const { total, arithmetic, harmonic, geometric, min, max } = average(times) console.log(`Total: ${total} ms`) console.log(`Average: ${arithmetic} ms`) console.log(`Harmonic: ${harmonic} ms`) console.log(`Geometric: ${geometric} ms`) + console.log(`Minimum: ${min} ms`) + console.log(`Maximum: ${max} ms`) }) }) -- 2.34.1