]> git.codecow.com Git - nano-pow.git/commitdiff
Extract test page execution loop to separate function.
authorChris Duncan <chris@codecow.com>
Fri, 22 May 2026 19:36:36 +0000 (12:36 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 22 May 2026 19:36:36 +0000 (12:36 -0700)
test/index.html

index f77018e593f7b812cf4996a775b1d1fa9fb27444..49b92d845905fd0d469360fdbd8036c832f47981 100644 (file)
@@ -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 += '<br/>'
+                                       if (!isValid) console.log(hash, result, check)
+                               }
+                       }
+                       return times
+               }
+
                function startValidation (event) {
                        const difficulty = document.getElementById('difficulty')?.value
                        const work = document.getElementById('work')?.value