From fada0cc1738bb267cde8bcc863dab766a2c0e0b7 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 4 Jan 2025 04:04:29 -0800 Subject: [PATCH] Add PowGpu performance tests outside of Block scope and Web Workers. --- perf/block.perf.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/perf/block.perf.js b/perf/block.perf.js index 0376b00..4719d48 100644 --- a/perf/block.perf.js +++ b/perf/block.perf.js @@ -5,13 +5,37 @@ import { assert, average, skip, suite, test } from '#GLOBALS.mjs' import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' -import { SendBlock } from '#dist/main.js' +import { PowGpu, SendBlock } from '#dist/main.js' import 'nano-webgl-pow' await suite('Block performance', async () => { - const COUNT = 0x1 + const COUNT = 0x10 - await test(`Customized PoW: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => { + await test(`Customized PoW: Time to calculate proof-of-work for a block hash ${COUNT} times`, async () => { + const times = [] + const hashes = [ + NANO_TEST_VECTORS.PRIVATE_0, + NANO_TEST_VECTORS.PRIVATE_1, + NANO_TEST_VECTORS.PRIVATE_2, + NANO_TEST_VECTORS.PUBLIC_0, + NANO_TEST_VECTORS.PUBLIC_1, + NANO_TEST_VECTORS.PUBLIC_2 + ] + for (let i = 0; i < 6; i++) { + const start = performance.now() + const work = await PowGpu.find(hashes[i]) + const end = performance.now() + times.push(end - start) + console.log(`${work} (${end - start} ms) ${hashes[i]}`) + } + const { total, arithmetic, harmonic, geometric } = average(times) + console.log(`Total: ${total} ms`) + console.log(`Average: ${arithmetic} ms`) + console.log(`Harmonic: ${harmonic} ms`) + console.log(`Geometric: ${geometric} ms`) + }) + + await skip(`Customized PoW: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => { const times = [] const block = new SendBlock( NANO_TEST_VECTORS.SEND_BLOCK.account, @@ -26,7 +50,8 @@ await suite('Block performance', async () => { await block.pow() const end = performance.now() times.push(end - start) - console.log(`${block.work} (${end - start} ms)`) + console.log(`${block.work} (${end - start} ms) ${block.previous}`) + block.previous = 'BB569136FA05F8CBF65CEF2EDE368475B289C4477342976556BA4C0DDF216E45' } const { total, arithmetic, harmonic, geometric } = average(times) console.log(`Total: ${total} ms`) -- 2.34.1