]> zoso.dev Git - libnemo.git/commitdiff
Add test to compare original PoW lib to our modifications.
authorChris Duncan <chris@zoso.dev>
Fri, 13 Dec 2024 22:18:00 +0000 (14:18 -0800)
committerChris Duncan <chris@zoso.dev>
Fri, 13 Dec 2024 22:18:00 +0000 (14:18 -0800)
perf/block.perf.js

index ba814da6c2267e45a23d1975e6b10eb1d098fb57..50050d48e9a8ba59b8dcc48ff27c4289014b9ed9 100644 (file)
@@ -6,11 +6,31 @@
 import { assert, average, skip, suite, test } from '#GLOBALS.mjs'
 import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js'
 import { SendBlock, ReceiveBlock } from '#dist/main.js'
+import 'nano-webgl-pow'
 
 await suite('Block performance', async () => {
        const COUNT = 0x1
 
-       await test(`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 = []
+               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')
+                       })
+                       const end = performance.now()
+                       times.push(end - start)
+                       console.log(`${work} (${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(
                        NANO_TEST_VECTORS.SEND_BLOCK.account,
@@ -34,7 +54,7 @@ await suite('Block performance', async () => {
                console.log(`Geometric: ${geometric} ms`)
        })
 
-       await test(`Time to calculate proof-of-work for a receive block ${COUNT} times`, async () => {
+       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,