From 77f264e699b47d9f60918464fd7f6dd84e26c034 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 16 Dec 2024 14:57:07 -0800 Subject: [PATCH] Reorder block performance tests. --- perf/block.perf.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/perf/block.perf.js b/perf/block.perf.js index 50050d4..a1dcb34 100644 --- a/perf/block.perf.js +++ b/perf/block.perf.js @@ -11,17 +11,22 @@ import 'nano-webgl-pow' await suite('Block performance', async () => { const COUNT = 0x1 - await test(`Original PoW module: 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 send block ${COUNT} times`, async () => { const times = [] + const block = new SendBlock( + NANO_TEST_VECTORS.SEND_BLOCK.account, + NANO_TEST_VECTORS.SEND_BLOCK.balance, + NANO_TEST_VECTORS.SEND_BLOCK.link, + '0', + NANO_TEST_VECTORS.SEND_BLOCK.representative, + NANO_TEST_VECTORS.SEND_BLOCK.previous + ) for (let i = 0; i < COUNT; i++) { const start = performance.now() - const work = await new Promise(resolve => { - //@ts-expect-error - window.NanoWebglPow(NANO_TEST_VECTORS.SEND_BLOCK.previous, resolve, undefined, '0xFFFFFFF8') - }) + await block.pow() const end = performance.now() times.push(end - start) - console.log(`${work} (${end - start} ms)`) + console.log(`${block.work} (${end - start} ms)`) } const { total, arithmetic, harmonic, geometric } = average(times) console.log(`Total: ${total} ms`) @@ -30,22 +35,17 @@ await suite('Block performance', async () => { console.log(`Geometric: ${geometric} ms`) }) - await test(`Customized PoW: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => { + await test(`Original PoW module: 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, - NANO_TEST_VECTORS.SEND_BLOCK.balance, - NANO_TEST_VECTORS.SEND_BLOCK.link, - '0', - NANO_TEST_VECTORS.SEND_BLOCK.representative, - NANO_TEST_VECTORS.SEND_BLOCK.previous - ) for (let i = 0; i < COUNT; i++) { const start = performance.now() - await block.pow() + const work = await new Promise(resolve => { + //@ts-expect-error + window.NanoWebglPow(NANO_TEST_VECTORS.SEND_BLOCK.previous, resolve, undefined, '0xFFFFFFF8') + }) const end = performance.now() times.push(end - start) - console.log(`${block.work} (${end - start} ms)`) + console.log(`${work} (${end - start} ms)`) } const { total, arithmetic, harmonic, geometric } = average(times) console.log(`Total: ${total} ms`) -- 2.34.1