]> zoso.dev Git - libnemo.git/commitdiff
Add PowGpu performance tests outside of Block scope and Web Workers.
authorChris Duncan <chris@zoso.dev>
Sat, 4 Jan 2025 12:04:29 +0000 (04:04 -0800)
committerChris Duncan <chris@zoso.dev>
Sat, 4 Jan 2025 12:04:29 +0000 (04:04 -0800)
perf/block.perf.js

index 0376b000c349178f1df5d959fe6fad4028d3cf64..4719d480cb801e2c4374b5801d1539a90fb78de9 100644 (file)
@@ -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`)