]> zoso.dev Git - nano-pow.git/commitdiff
Pick out test page changes from other branch.
authorChris Duncan <chris@zoso.dev>
Thu, 16 Jan 2025 22:17:21 +0000 (14:17 -0800)
committerChris Duncan <chris@zoso.dev>
Thu, 16 Jan 2025 22:17:21 +0000 (14:17 -0800)
test.html

index 587e0041cb5b524706d578ff4e0737924372040f..e11a480eca3461527e26a84f9f792eae729948cb 100644 (file)
--- a/test.html
+++ b/test.html
@@ -65,8 +65,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        console.log(`Geometric Mean: ${geometric} ms`)
                }
 
-               export async function run (size, effort, gl, debug) {
-                       if (gl) NanoPow = NanoPowGl
+               export async function run (size, effort, isOutputShown, isGlForced, isDebug) {
+                       if (isGlForced) NanoPow = NanoPowGl
                        document.getElementById('status').innerHTML = `TESTING IN PROGRESS`
                        console.log(`%cNanoPow`, 'color:green', 'Checking validate()')
                        const expectFalse = await NanoPow.validate('0000000000000000', '0000000000000000000000000000000000000000000000000000000000000000')
@@ -95,17 +95,18 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                let work = null
                                const start = performance.now()
                                try {
-                                       work = await NanoPow.search(hash, { effort, debug })
+                                       work = await NanoPow.search(hash, { effort, debug: isDebug })
                                } catch (err) {
                                        document.getElementById('output').innerHTML += `Error: ${err.message}<br/>`
                                        console.error(err)
                                }
                                const end = performance.now()
+                               document.getElementById('status').innerHTML = `TESTING IN PROGRESS ${i}/${size}<br/>`
                                const isValid = (await NanoPow.validate(work, hash)) ? 'VALID' : 'INVALID'
                                times.push(end - start)
                                const msg = `${isValid} [${work}] ${hash} (${end - start} ms)`
                                // console.log(msg)
-                               document.getElementById('output').innerHTML += `${msg}<br/>`
+                               if (isOutputShown) document.getElementById('output').innerHTML += `${msg}<br/>`
                        }
                        document.getElementById('output').innerHTML += `-----<br/>`
                        document.getElementById('summary').innerHTML += `NanoPow (${type})<br/>${JSON.stringify(average(times), null, '\t')}<br/>`
@@ -135,9 +136,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
                document.getElementById('go').addEventListener('click', e => {
                        const size = document.getElementById('size')
                        const effort = document.getElementById('effort')
-                       const gl = document.getElementById('gl')
-                       const debug = document.getElementById('debug')
-                       run(size.value, effort.value, gl.checked, debug.checked)
+                       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)
                })
        </script>
        <style>body{background:black;color:white;}a{color:darkcyan;}input[type=number]{width:5em;}</style>
@@ -163,10 +165,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
        <input id="size" type="number" value="64" />
        <label for="effort">Effort (1-16)</label>
        <input id="effort" type="number" value="8" min="1" max="16" />
-       <label for="gl">Force WebGL?</label>
-       <input id="gl" type="checkbox" />
-       <label for="debug">Debug?</label>
-       <input id="debug" type="checkbox" />
+       <label for="isOutputShown">Show output?</label>
+       <input id="isOutputShown" type="checkbox" />
+       <label for="isGlForced">Force WebGL?</label>
+       <input id="isGlForced" type="checkbox" />
+       <label for="isDebug">Debug?</label>
+       <input id="isDebug" type="checkbox" />
        <button id="go">Go</button>
        <h3 id="status">WAITING</h3>
        <hr />