From 3dfda09d227ad6e9c80c07a40aab68f0a044c445 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 16 Jun 2025 08:01:55 -0700 Subject: [PATCH] Add scoring function to test page and start at 100 runs of 100 samples. --- test/index.html | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/index.html b/test/index.html index 19b73f6..d072fe7 100644 --- a/test/index.html +++ b/test/index.html @@ -175,6 +175,42 @@ SPDX-License-Identifier: GPL-3.0-or-later console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold') } + export async function score () { + const rates = [] + for (let i = 0; i < 100; i++) { + const times = [] + console.log(`%cNanoPow`, 'color:green', `Calculate proof-of-work for 1000 unique send block hashes`) + for (let j = 0; j < 100; j++) { + document.getElementById('status').innerHTML = `SCORING IN PROGRESS. THIS WILL TAKE A LONG TIME. ${i}/100 ${j}/1000
` + const hash = random() + let result = null + const start = performance.now() + try { + result = await NanoPow.work_generate(hash) + } catch (err) { + document.getElementById('output').innerHTML += `Error: ${err.message}
` + console.error(err) + return + } + times.push(performance.now() - start) + } + const results = Object.values(average(times))[0] + console.log(times) + console.log(results) + const { truncatedRate } = results + rates.push(truncatedRate) + document.getElementById('output').innerHTML += `Truncated Rate ${i}: ${truncatedRate}
` + } + const results = Object.values(average(rates))[0] + console.log(rates) + console.log(results) + const { truncatedHarmonic } = results + document.getElementById('output').innerHTML += `
` + document.getElementById('summary').innerHTML += `Score: ${truncatedHarmonic} wps
` + document.getElementById('status').innerHTML = `SCORING COMPLETE
` + console.log('%cSCORING COMPLETE', 'color:orange;font-weight:bold') + } + function startValidation (event) { const difficulty = document.getElementById('difficulty')?.value const work = document.getElementById('work')?.value @@ -222,7 +258,14 @@ SPDX-License-Identifier: GPL-3.0-or-later isSelfCheck.checked = false }) } + + function startScore (event) { + event.target.disabled = true + score().then(() => event.target.disabled = false) + } + document.getElementById('btnStartTest').addEventListener('click', startTest) + document.getElementById('btnStartScore').addEventListener('click', startScore) document.getElementById('effort').value = Math.max(1, Math.floor(navigator.hardwareConcurrency) / 2)