From 801ce2fb4885d748132c2f4f12b3dbb258a8a954 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 22 May 2026 12:54:45 -0700 Subject: [PATCH] Implement execution loop for runs and scoring. --- test/index.html | 50 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/test/index.html b/test/index.html index 2a17bc7..6c87177 100644 --- a/test/index.html +++ b/test/index.html @@ -179,25 +179,15 @@ SPDX-License-Identifier: GPL-3.0-or-later } console.log(`%cNanoPow (${type})`, 'color:green', `Calculate proof-of-work for ${size} unique send block hashes`) - const times = [] - for (let i = 0; i < size; i++) { - document.getElementById('status').innerHTML = `TESTING IN PROGRESS ${i}/${size}
` - const hash = random() - let result = null - const start = performance.now() - try { - result = await NanoPow.work_generate(hash, { api, difficulty, effort, debug: isDebug }) - } catch (err) { - document.getElementById('output').innerHTML += `Error: ${err.message}
` - console.error(err) - return - } - const end = performance.now() - const check = await NanoPow.work_validate(result.work, result.hash, { difficulty, debug: isDebug }) - const isValid = (result.hash === hash && check.valid === '1') ? 'VALID' : 'INVALID' - times.push(end - start) - const msg = `${isValid} (${end - start} ms)\n${JSON.stringify(result, ' ', 2)}` - if (isOutputShown) document.getElementById('output').innerHTML += `${msg}
` + document.getElementById('status').innerHTML = `TESTING IN PROGRESS 0/${size}
` + let times + try { + times = await execute(size, difficulty, effort, api, isOutputShown) + } catch (err) { + output.textContent += `Error: ${err.message}` + output.innerHTML += '
' + console.error(err) + return } document.getElementById('output').innerHTML += `
` document.getElementById('summary').innerHTML += `${JSON.stringify(average(times, type, effort), null, '\t')}
` @@ -209,20 +199,14 @@ SPDX-License-Identifier: GPL-3.0-or-later console.log(`%cNanoPow ${api}`, 'color:green', `Calculate truncated harmonic mean of the truncated arithmetic rate across ${runs} runs of ${size} samples.`) const rates = [] for (let i = 0; i < runs; i++) { - const times = [] - for (let j = 0; j < size; j++) { - document.getElementById('status').innerHTML = `SCORING IN PROGRESS. THIS WILL TAKE A LONG TIME. ${i}/${runs} ${j}/${size}
` - const hash = random() - let result = null - const start = performance.now() - try { - result = await NanoPow.work_generate(hash, { difficulty, effort, api }) - } catch (err) { - document.getElementById('output').innerHTML += `Error: ${err.message}
` - console.error(err) - return - } - times.push(performance.now() - start) + let times + document.getElementById('status').innerHTML = `SCORING IN PROGRESS. THIS WILL TAKE A LONG TIME. ${i}/${runs} 0/${size}
` + try { + times = await execute(runs, size, difficulty, effort, api) + } catch (err) { + document.getElementById('output').innerHTML += `Error: ${err.message}
` + console.error(err) + return } const results = Object.values(average(times))[0] const { truncatedRate } = results -- 2.52.0