]> zoso.dev Git - libnemo.git/commitdiff
Add a few logs for perf testing.
authorChris Duncan <chris@zoso.dev>
Sun, 1 Dec 2024 06:06:29 +0000 (22:06 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 1 Dec 2024 06:06:29 +0000 (22:06 -0800)
src/lib/pool.ts
src/lib/wallet.ts
src/lib/workers/ckdBip44.ts
src/lib/workers/nano-nacl.ts

index e66472009f44e50c1672a4da7d1ee1525ea18775..edb5b3784fb2f2fddb98587b5f7f7fb091843fd0 100644 (file)
@@ -34,7 +34,6 @@ export class Pool {
        }
 
        constructor (fn: string) {
-               console.log(`cores: ${this.#cores}`)
                const url = URL.createObjectURL(new Blob([fn], { type: 'text/javascript' }))
                for (let i = this.#cores; i > 0; i--) {
                        const thread = {
@@ -43,6 +42,7 @@ export class Pool {
                                worker: new Worker(url, { type: 'module', eval: true })
                        }
                        thread.worker.addEventListener('message', (message) => {
+                               console.log(`received worker response (${performance.now()})`)
                                let result = JSON.parse(new TextDecoder().decode(message.data ?? message))
                                if (!Array.isArray(result)) result = [result]
                                this.#report(thread, result)
@@ -55,7 +55,7 @@ export class Pool {
                if (next.length > 0) {
                        thread.isBusy = true
                        const buf = new TextEncoder().encode(JSON.stringify(next)).buffer
-                       console.log(`posting to ${thread} (${performance.now()})`)
+                       console.log(`posting to thread (${performance.now()})`)
                        thread.worker.postMessage(buf, [buf])
                }
        }
@@ -71,6 +71,7 @@ export class Pool {
        }
 
        async work (data: object[]): Promise<any> {
+               console.log(`pool.work (${performance.now()})`)
                if (!Array.isArray(data)) data = [data]
                return new Promise(resolve => {
                        this.#queue = data
index 398c47717dd91ce542c1158003bf0505a5e27303..2ddca767961a59d0955a4aeb81a602ffe74a4e38 100644 (file)
@@ -98,8 +98,6 @@ abstract class Wallet {
                        let results = await this.ckd(indexes)\r
                        const data: any = []\r
                        results.forEach(r => data.push({ privateKey: r.privateKey, index: r.index }))\r
-                       console.log(`accounts data`)\r
-                       console.dir(data)\r
                        let now = performance.now()\r
                        const keypairs: KeyPair[] = await this.#pool.work(data)\r
                        console.log(`keypairs: ${-now + (now = performance.now())} ms`)\r
index 99a8ed855532bc99647df19172ef41ae93435f7b..c1f1294cce893ed18efa20cb8337c637127a7c7e 100644 (file)
@@ -16,6 +16,7 @@ const Bip44Ckd = () => {
        * Listens for messages from a calling function.
        */
        addEventListener('message', (message) => {
+               console.log(`bip44ckd work received (${performance.now()})`)
                const data = JSON.parse(new TextDecoder().decode(message.data ?? message))
                process(data).then(results => {
                        const buf = new TextEncoder().encode(JSON.stringify(results)).buffer
index 3cea4a085759b00114e8f3fe0477ebddb894ebe5..deeb9ec3c4398b0a5339d3418fa1c58ba40e76cd 100644 (file)
@@ -20,12 +20,16 @@ const NanoNaCl = () => {
        * Listens for messages from a calling function.\r
        */\r
        addEventListener('message', (message) => {\r
+               console.log(`nacl work received (${performance.now()})`)\r
                const data = JSON.parse(new TextDecoder().decode(message.data ?? message))\r
-               for (const d of data) {\r
-                       d.publicKey = hexify(keyPair(d.privateKey).publicKey)\r
+               // for (const d of data) {\r
+               for (let i = 0; i < data.length; i++) {\r
+                       if (i % 100 === 0) console.log(`${i} keys`)\r
+                       data[i].publicKey = hexify(keyPair(data[i].privateKey).publicKey)\r
                }\r
                const buf = new TextEncoder().encode(JSON.stringify(data)).buffer\r
                //@ts-expect-error\r
+               console.log(`nacl work done (${performance.now()})`)\r
                postMessage(buf, [buf])\r
        })\r
 \r