From: Chris Duncan Date: Wed, 18 Dec 2024 23:51:46 +0000 (-0800) Subject: Test receive block first. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=182e36e095bd2c488443eb9e677651c3d8e1dc72;p=libnemo.git Test receive block first. --- diff --git a/perf/block.perf.js b/perf/block.perf.js index a1dcb34..6ee56c5 100644 --- a/perf/block.perf.js +++ b/perf/block.perf.js @@ -11,6 +11,30 @@ import 'nano-webgl-pow' await suite('Block performance', async () => { const COUNT = 0x1 + await test(`Customized PoW: Time to calculate proof-of-work for a receive block ${COUNT} times`, async () => { + const times = [] + const block = new ReceiveBlock( + NANO_TEST_VECTORS.RECEIVE_BLOCK.account, + NANO_TEST_VECTORS.RECEIVE_BLOCK.balance, + NANO_TEST_VECTORS.RECEIVE_BLOCK.link, + '0', + NANO_TEST_VECTORS.RECEIVE_BLOCK.representative, + NANO_TEST_VECTORS.RECEIVE_BLOCK.previous + ) + for (let i = 0; i < COUNT; i++) { + const start = performance.now() + await block.pow() + const end = performance.now() + times.push(end - start) + console.log(`${end - start} ms`) + } + 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 test(`Customized PoW: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => { const times = [] const block = new SendBlock( @@ -53,28 +77,4 @@ await suite('Block performance', async () => { console.log(`Harmonic: ${harmonic} ms`) console.log(`Geometric: ${geometric} ms`) }) - - await test(`Customized PoW: Time to calculate proof-of-work for a receive block ${COUNT} times`, async () => { - const times = [] - const block = new ReceiveBlock( - NANO_TEST_VECTORS.RECEIVE_BLOCK.account, - NANO_TEST_VECTORS.RECEIVE_BLOCK.balance, - NANO_TEST_VECTORS.RECEIVE_BLOCK.link, - '0', - NANO_TEST_VECTORS.RECEIVE_BLOCK.representative, - NANO_TEST_VECTORS.RECEIVE_BLOCK.previous - ) - for (let i = 0; i < COUNT; i++) { - const start = performance.now() - await block.pow() - const end = performance.now() - times.push(end - start) - console.log(`${end - start} ms`) - } - 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`) - }) })