From: Chris Duncan Date: Mon, 9 Nov 2026 15:37:36 +0000 (-0800) Subject: Integrate bulk block verification into nano25519 API speed test. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=0ed856ff1d28123b4ceec351006c41819d76a30e;p=nano25519.git Integrate bulk block verification into nano25519 API speed test. --- diff --git a/test/index.html b/test/index.html index dd40d6f..ce95f71 100644 --- a/test/index.html +++ b/test/index.html @@ -424,12 +424,15 @@ SPDX-License-Identifier: GPL-3.0-or-later const signRates = [] const verifyTimes = [] const verifyRates = [] + const verifyBlocksTimes = [] + const verifyBlocksRates = [] for (let i = 0; i < runs; i++) { await new Promise(r => setTimeout(r)) deriveTimes[i] = [] signTimes[i] = [] verifyTimes[i] = [] + verifyBlocksTimes[i] = [] for (let j = 0; j < size; j++) { document.getElementById('status').innerHTML = `TESTING IN PROGRESS. THIS MAY TAKE A LONG TIME. ${i}/${runs} ${j}/${size}
` @@ -437,9 +440,30 @@ SPDX-License-Identifier: GPL-3.0-or-later start = end = duration = 0 try { - if (api === 'nano25519 with bulk block verification') { - privateKey = rand(32).bytes - publicKey = derive(privateKey, 'nano25519') + privateKey = rand(32).bytes + message = rand(bytes).bytes + + start = performance.now() + publicKey = derive(privateKey, api) + end = performance.now() + duration = end - start + deriveTimes[i].push(duration) + + start = performance.now() + signature = sign(message, privateKey, publicKey, api) + end = performance.now() + duration = end - start + signTimes[i].push(duration) + + start = performance.now() + if (!verify(signature, message, publicKey, api)) { + throw new Error(`invalid result\nsignature: ${signature}\nblock hash: ${message}\npublic key: ${publicKey}`) + } + end = performance.now() + duration = end - start + verifyTimes[i].push(duration) + + if (api === 'nano25519' && i === 0) { const blocks = [] for (let b = 0; b < nano25519.constants.MAX_VERIFY_BLOCKS; b++) { message = rand(32).bytes @@ -451,36 +475,12 @@ SPDX-License-Identifier: GPL-3.0-or-later end = performance.now() for (let i = 0; i < verified.length; i++) { if (verified[i] !== true) { - throw new Error(`invalid result ${verified[i]}\nsignature: ${blocks[i].signature}\nblock hash: ${blocks[i].hash}\npublic key: ${publicKey}`) + throw new Error(`invalid verify_blocks result ${verified[i]}\nsignature: ${blocks[i].signature}\nblock hash: ${blocks[i].hash}\npublic key: ${publicKey}`) } } duration = (end - start) / nano25519.constants.MAX_VERIFY_BLOCKS - deriveTimes[i].push(0) - signTimes[i].push(0) - verifyTimes[i].push(duration) - } else { - privateKey = rand(32).bytes - message = rand(bytes).bytes - - start = performance.now() - publicKey = derive(privateKey, api) - end = performance.now() - duration = end - start - deriveTimes[i].push(duration) - - start = performance.now() - signature = sign(message, privateKey, publicKey, api) - end = performance.now() - duration = end - start - signTimes[i].push(duration) - - start = performance.now() - if (!verify(signature, message, publicKey, api)) { - throw new Error(`invalid result\nsignature: ${signature}\nblock hash: ${message}\npublic key: ${publicKey}`) - } - end = performance.now() - duration = end - start - verifyTimes[i].push(duration) + verifyBlocksTimes[i].push(duration) + verifyBlocksRates.push(stats(verifyBlocksTimes[i]).truncatedRate) } } catch (err) { document.getElementById('output').innerHTML += `Error: ${err.message}
` @@ -495,12 +495,14 @@ SPDX-License-Identifier: GPL-3.0-or-later const deriveResults = stats(deriveRates) const signResults = stats(signRates) const verifyResults = stats(verifyRates) + const verifyBlocksResults = stats(verifyBlocksRates) document.getElementById('status').textContent = 'TESTING COMPLETE' const summary = document.createElement('pre') summary.textContent += `${api} derive: ${deriveResults.truncatedHarmonic} per second\n` summary.textContent += `${api} sign: ${signResults.truncatedHarmonic} per second\n` summary.textContent += `${api} verify: ${verifyResults.truncatedHarmonic} per second\n` + if (api === 'nano25519') summary.textContent += `${api} verify_blocks (batch of 64): ${verifyBlocksResults.truncatedHarmonic} per second per block\n` document.getElementById('summary').appendChild(summary) document.getElementById('summary').appendChild(document.createElement('hr')) @@ -508,29 +510,13 @@ SPDX-License-Identifier: GPL-3.0-or-later output.textContent += `${api} derive: ${JSON.stringify(stats(deriveTimes.flat()), null, 2)}\n` output.textContent += `${api} sign: ${JSON.stringify(stats(signTimes.flat()), null, 2)}\n` output.textContent += `${api} verify: ${JSON.stringify(stats(verifyTimes.flat()), null, 2)}\n` + if (api === 'nano25519') output.textContent += `${api} verify_blocks (batch of 64): ${JSON.stringify(stats(verifyBlocksTimes.flat()), null, 2)}\n` document.getElementById('output').appendChild(output) document.getElementById('output').appendChild(document.createElement('hr')) console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold') } function startValidation(event) { - const bytes = document.getElementById('bytes') - const size = document.getElementById('size') - const api = document.getElementById('api')?.value - if (api === 'nano25519 with bulk block verification') { - if (!size.disabled) { - bytes.value = nano25519.constants.BLOCKHASH_BYTELENGTH - bytes.disabled = true - size.value = nano25519.constants.MAX_VERIFY_BLOCKS - size.dataset.value = 1 - size.disabled = true - } - } else if (size.disabled) { - bytes.disabled = false - size.value = 100 - size.dataset.value = 0 - size.disabled = false - } const signature = document.getElementById('signature')?.value const blockHash = document.getElementById('blockHash')?.value const publicKey = document.getElementById('publicKey')?.value @@ -556,7 +542,7 @@ SPDX-License-Identifier: GPL-3.0-or-later const bytes = document.getElementById('bytes') const size = document.getElementById('size') const runs = document.getElementById('runs') - test(api.value, +bytes.value, +size.dataset.value ? 1 : +size.value, +runs.value) + test(api.value, +bytes.value, +size.value, +runs.value) .then(() => { event.target.disabled = false }) @@ -643,7 +629,6 @@ SPDX-License-Identifier: GPL-3.0-or-later