]> zoso.dev Git - libnemo.git/commitdiff
Performance testing. threads
authorChris Duncan <chris@zoso.dev>
Thu, 12 Dec 2024 00:12:35 +0000 (16:12 -0800)
committerChris Duncan <chris@zoso.dev>
Thu, 12 Dec 2024 00:12:35 +0000 (16:12 -0800)
perf/block.perf.js
perf/log [new file with mode: 0644]
src/lib/workers/pow.ts

index 00f6e570c3abed893389191f861b22ece0fe7db8..f82b700d025859ebb5c794042268b83941f83c52 100644 (file)
@@ -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 (file)
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
+
+​
index 4cdf7b07c388672a098e24112fcfc78a27782237..e5534bd2402f199b992aa2cc5f0d47b3267dda24 100644 (file)
@@ -41,6 +41,7 @@ export class Pow {
        }
 
        static calculate (hashHex: string, threshold: number | string = '0xFFFFFFF8', callback: (nonce: string | PromiseLike<string>) => 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)
        }