From: Chris Duncan Date: Thu, 12 Dec 2024 00:12:35 +0000 (-0800) Subject: Performance testing. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=refs%2Fheads%2Fthreads;p=libnemo.git Performance testing. --- diff --git a/perf/block.perf.js b/perf/block.perf.js index 00f6e57..f82b700 100644 --- a/perf/block.perf.js +++ b/perf/block.perf.js @@ -8,7 +8,7 @@ import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { SendBlock, ReceiveBlock } from '#dist/main.js' await suite('Block performance', async () => { - const COUNT = 0x10 + const COUNT = 0x1 await test('Time to calculate proof-of-work for a send block 0x10 times', async () => { const times = [] diff --git a/perf/log b/perf/log new file mode 100644 index 0000000..865242e --- /dev/null +++ b/perf/log @@ -0,0 +1,63 @@ +SEND BLOCK + +start calculate: 155 c88dd903-db2a-4aa6-b394-f60167006006:1497:17 +color cleared: 230 c88dd903-db2a-4aa6-b394-f60167006006:1511:17 +starting first draw: 234 c88dd903-db2a-4aa6-b394-f60167006006:1782:17 +start readPixels: 264 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 305 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 308 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 348 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 351 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 394 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 402 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 444 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 446 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 485 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 488 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 525 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 528 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 568 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 571 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 609 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 612 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 650 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 656 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 695 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 698 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 736 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 738 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 778 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 781 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 819 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 821 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 858 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +start readPixels: 861 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 900 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +found: 903 c88dd903-db2a-4aa6-b394-f60167006006:1770:23 + +Total: 900 ms block.perf.js:32:10 +Average: 900 ms block.perf.js:33:10 +Harmonic: 900 ms block.perf.js:34:10 +Geometric: 900 ms block.perf.js:35:10 + + + +RECEIVE BLOCK + +start calculate: 905 c88dd903-db2a-4aa6-b394-f60167006006:1497:17 +color cleared: 960 c88dd903-db2a-4aa6-b394-f60167006006:1511:17 +starting first draw: 963 c88dd903-db2a-4aa6-b394-f60167006006:1782:17 +start readPixels: 969 c88dd903-db2a-4aa6-b394-f60167006006:1765:19 +end readPixels: 1008 c88dd903-db2a-4aa6-b394-f60167006006:1767:19 +found: 1008 c88dd903-db2a-4aa6-b394-f60167006006:1770:23 + + +Total: 104 ms block.perf.js:56:10 +Average: 104 ms block.perf.js:57:10 +Harmonic: 104 ms block.perf.js:58:10 +Geometric: 104 ms block.perf.js:59:10 + +PASS Time to calculate proof-of-work for a receive block 0x10 times GLOBALS.mjs:42:9 +TESTING COMPLETE main.mjs:8:8 + +​ diff --git a/src/lib/workers/pow.ts b/src/lib/workers/pow.ts index 4cdf7b0..e5534bd 100644 --- a/src/lib/workers/pow.ts +++ b/src/lib/workers/pow.ts @@ -41,6 +41,7 @@ export class Pow { } static calculate (hashHex: string, threshold: number | string = '0xFFFFFFF8', callback: (nonce: string | PromiseLike) => any): void { + console.log(`start calculate: ${performance.now()}`) if (typeof threshold === 'number') threshold = '0x' + threshold.toString(16) if (!/^[A-F-a-f0-9]{64}$/.test(hashHex)) throw new Error(`invalid_hash ${hashHex}`) let reverseHex = '' @@ -56,6 +57,7 @@ export class Pow { gl.clearColor(0, 0, 0, 1) + console.log(`color cleared: ${performance.now()}`) // Vertext Shader const vsSource = `#version 300 es @@ -305,11 +307,15 @@ export class Pow { gl.clear(gl.COLOR_BUFFER_BIT) gl.drawArrays(gl.TRIANGLES, 0, 6) const pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4) + + console.log(`start readPixels: ${performance.now()}`) gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels) + console.log(`end readPixels: ${performance.now()}`) // Check the pixels for any success for (let i = 0; i < pixels.length; i += 4) { if (pixels[i] !== 0) { + console.log(`found: ${performance.now()}`) // Return the work value with the custom bits typeof callback === 'function' && callback(this.hexify(work1) + this.hexify([ @@ -325,6 +331,7 @@ export class Pow { self.requestAnimationFrame(draw) } + console.log(`starting first draw: ${performance.now()}`) // Begin generation self.requestAnimationFrame(draw) }