From c9db000f46e665d2ded4eaabb909759676ab273f Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 20 Jan 2025 10:51:23 -0800 Subject: [PATCH] Add custom threshold to test page. --- test.html | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test.html b/test.html index c00e919..4e3cc22 100644 --- a/test.html +++ b/test.html @@ -60,7 +60,7 @@ SPDX-License-Identifier: GPL-3.0-or-later } } - export async function run (size, effort, isOutputShown, isGlForced, isDebug) { + export async function run (threshold, size, effort, isOutputShown, isGlForced, isDebug) { if (isGlForced) NanoPow = NanoPowGl document.getElementById('status').innerHTML = `TESTING IN PROGRESS 0/${size}` console.log(`%cNanoPow`, 'color:green', 'Checking validate()') @@ -90,17 +90,16 @@ SPDX-License-Identifier: GPL-3.0-or-later let work = null const start = performance.now() try { - work = await NanoPow.search(hash, { threshold: 0, effort, debug: isDebug }) + work = await NanoPow.search(hash, { threshold, effort, debug: isDebug }) } catch (err) { document.getElementById('output').innerHTML += `Error: ${err.message}
` console.error(err) + return } const end = performance.now() - // const isValid = (await NanoPow.validate(work, hash, { threshold: 0 })) ? 'VALID' : 'INVALID' - const isValid = 'Valid' + const isValid = (await NanoPow.validate(work, hash, { threshold: 0 })) ? 'VALID' : 'INVALID' times.push(end - start) const msg = `${isValid} [${work}] ${hash} (${end - start} ms)` - // console.log(msg) if (isOutputShown) document.getElementById('output').innerHTML += `${msg}
` } document.getElementById('output').innerHTML += `
` @@ -110,11 +109,12 @@ SPDX-License-Identifier: GPL-3.0-or-later } function startValidation (event) { + const threshold = document.getElementById('threshold') const work = document.getElementById('work') const hash = document.getElementById('hash') const validation = document.getElementById('validation') validation.innerText = '' - NanoPow.validate(work.value, hash.value) + NanoPow.validate(work.value, hash.value, { threshold: `0x${+threshold.value}` }) .then(result => { validation.innerText = result ? 'Valid' @@ -128,12 +128,13 @@ SPDX-License-Identifier: GPL-3.0-or-later document.getElementById('btnStartValidation').addEventListener('click', startValidation) function startTest (event) { + const threshold = document.getElementById('threshold') const size = document.getElementById('size') const effort = document.getElementById('effort') const isOutputShown = document.getElementById('isOutputShown') const isGlForced = document.getElementById('isGlForced') const isDebug = document.getElementById('isDebug') - run(+size.value, +effort.value, isOutputShown.checked, isGlForced.checked, isDebug.checked) + run(+`0x${threshold.value}`, +size.value, +effort.value, isOutputShown.checked, isGlForced.checked, isDebug.checked) } document.getElementById('btnStartTest').addEventListener('click', startTest) @@ -149,6 +150,9 @@ SPDX-License-Identifier: GPL-3.0-or-later

Times below are in milliseconds and are summarized by various averaging methods.

Level of Effort depends on hardware and does not guarantee faster results.


+ + +
@@ -157,7 +161,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
- + -- 2.34.1