From: Chris Duncan Date: Fri, 22 May 2026 19:36:36 +0000 (-0700) Subject: Extract test page execution loop to separate function. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=c2929288cb968e0f5e1c6020f0fb7b997ddcc199;p=nano-pow.git Extract test page execution loop to separate function. --- diff --git a/test/index.html b/test/index.html index f77018e..49b92d8 100644 --- a/test/index.html +++ b/test/index.html @@ -238,6 +238,29 @@ SPDX-License-Identifier: GPL-3.0-or-later console.log('%cSCORING COMPLETE', 'color:orange;font-weight:bold') } + async function execute (size, difficulty, effort, api, isOutputShown, isDebug) { + Cache.clear() + const output = document.getElementById('output') + const times = [] + let hash, result, start, end, check, isValid + for (let i = 0; i < size; i++) { + document.getElementById('status').textContent.replace(`${(i || 1) - 1}/${size}`, `${i}/${size}`) + hash = random() + start = performance.now() + result = await NanoPow.work_generate(hash, { difficulty, effort, api }) + end = performance.now() + times.push(end - start) + check = await NanoPow.work_validate(result.work, result.hash, { difficulty, debug: isDebug }) + isValid = (result.hash === hash && check.hash === hash && check.valid === '1') + if (isOutputShown) { + output.textContent += `${isValid ? 'VALID' : 'INVALID'} (${end - start} ms)\n${JSON.stringify(result, ' ', 2)}` + output.innerHTML += '
' + if (!isValid) console.log(hash, result, check) + } + } + return times + } + function startValidation (event) { const difficulty = document.getElementById('difficulty')?.value const work = document.getElementById('work')?.value