]> git.codecow.com Git - nano-pow.git/commitdiff
Add scoring function to test page and start at 100 runs of 100 samples.
authorChris Duncan <chris@zoso.dev>
Mon, 16 Jun 2025 15:01:55 +0000 (08:01 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 16 Jun 2025 15:01:55 +0000 (08:01 -0700)
test/index.html

index 19b73f68740b007b3331f7f415a2d9d40d5ca696..d072fe7039506d9ed9408ee336e1f2d5b0389e47 100644 (file)
@@ -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<br/>`
+                                       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}<br/>`
+                                               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}<br/>`
+                       }
+                       const results = Object.values(average(rates))[0]
+                       console.log(rates)
+                       console.log(results)
+                       const { truncatedHarmonic } = results
+                       document.getElementById('output').innerHTML += `<hr/>`
+                       document.getElementById('summary').innerHTML += `Score: ${truncatedHarmonic} wps<br/>`
+                       document.getElementById('status').innerHTML = `SCORING COMPLETE<br/>`
+                       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)
        </script>
        <style>
@@ -277,6 +320,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
                <input id="isSelfCheck" type="checkbox" checked />
        </span>
        <button id="btnStartTest">Go</button>
+       <hr />
+       <button id="btnStartScore">Score ❗</button>
        <h3 id="status">WAITING</h3>
        <hr />
        <pre id="summary"></pre>