From: Chris Duncan Date: Thu, 27 Aug 2026 04:53:41 +0000 (-0700) Subject: Extract verification speed test so that blocks can be constructed prior to timing. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=447c5bc31e4b7339d17eb7448e4e37ad3ec681a8;p=nano25519.git Extract verification speed test so that blocks can be constructed prior to timing. --- diff --git a/test/index.html b/test/index.html index 8f3cdbd..5f511f8 100644 --- a/test/index.html +++ b/test/index.html @@ -178,12 +178,6 @@ SPDX-License-Identifier: GPL-3.0-or-later case 'nano25519': { return nano25519.verify(sig8, msg8, pub8) } - case 'nano25519 with bulk block verification': { - const blocks = [] - for (let i = 0; i < 256; i++) blocks[i] = { hash: msg8, signature: sig8 } - const verified = nano25519.verify_blocks(pub8, blocks) - return verified.every(v => v === true) - } case 'NanocurrencyWeb': { return NanocurrencyWeb.tools.verify(pub, sig, msg) } @@ -384,26 +378,44 @@ SPDX-License-Identifier: GPL-3.0-or-later privateKey = random() try { - start = performance.now() - publicKey = derive(privateKey, api) - end = performance.now() - duration = end - start - deriveTimes[i].push(duration) - - start = performance.now() - signature = sign(blockHash, privateKey, publicKey, api) - end = performance.now() - duration = end - start - signTimes[i].push(duration) - - start = performance.now() - if (!verify(signature, blockHash, publicKey, api)) { - throw new Error(`invalid result\nsignature: ${signature}\nblock hash: ${blockHash}\npublic key: ${publicKey}`) + if (api === 'nano25519 with bulk block verification') { + publicKey = derive(privateKey, 'nano25519') + signature = sign(blockHash, privateKey, publicKey, 'nano25519') + const blocks = [] + for (let i = 0; i < 256; i++) { + blocks[i] = { hash: blockHash, signature } + } + start = performance.now() + const verified = nano25519.verify_blocks(publicKey, blocks) + end = performance.now() + if (verified.some(v => v !== true)) { + throw new Error(`invalid result\nsignature: ${signature}\nblock hash: ${blockHash}\npublic key: ${publicKey}`) + } + duration = (end - start) / 256 + deriveTimes[i].push(0) + signTimes[i].push(0) + verifyTimes[i].push(duration) + } else { + start = performance.now() + publicKey = derive(privateKey, api) + end = performance.now() + duration = end - start + deriveTimes[i].push(duration) + + start = performance.now() + signature = sign(blockHash, privateKey, publicKey, api) + end = performance.now() + duration = end - start + signTimes[i].push(duration) + + start = performance.now() + if (!verify(signature, blockHash, publicKey, api)) { + throw new Error(`invalid result\nsignature: ${signature}\nblock hash: ${blockHash}\npublic key: ${publicKey}`) + } + end = performance.now() + duration = end - start + verifyTimes[i].push(duration) } - end = performance.now() - duration = end - start - duration /= (api === 'nano25519 with bulk block verification') ? 256 : 1 - verifyTimes[i].push(duration) } catch (err) { document.getElementById('output').innerHTML += `Error: ${err.message}
` console.error(err)