]> zoso.dev Git - libnemo.git/commitdiff
Reorder block performance tests.
authorChris Duncan <chris@zoso.dev>
Mon, 16 Dec 2024 22:57:07 +0000 (14:57 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 16 Dec 2024 22:57:07 +0000 (14:57 -0800)
perf/block.perf.js

index 50050d48e9a8ba59b8dcc48ff27c4289014b9ed9..a1dcb3430159bf38eb072f93532aceed69959c3c 100644 (file)
@@ -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`)