]> git.codecow.com Git - nano-pow.git/commitdiff
Generate one zero-difficulty nonce to compile. Add parameters from page to score...
authorChris Duncan <chris@zoso.dev>
Mon, 16 Jun 2025 17:51:39 +0000 (10:51 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 16 Jun 2025 17:51:39 +0000 (10:51 -0700)
test/index.html

index d072fe7039506d9ed9408ee336e1f2d5b0389e47..ca0a5b71e14addaac462cc8b425cb4ef6726214d 100644 (file)
@@ -52,7 +52,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        }
                }
 
-               export async function run (difficulty, size, effort, isOutputShown, api, isDebug, isSelfCheck) {
+               export async function run (size, difficulty, effort, api, isOutputShown, isDebug, isSelfCheck) {
+                       // Generate once on load to compile shaders and initialize buffers
+                       await NanoPow.work_generate(random(), { api, difficulty: 0 })
                        const type = api
                        api = type.toLowerCase()
                        if (isSelfCheck) {
@@ -175,18 +177,18 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold')
                }
 
-               export async function score () {
+               export async function score (runs, size, difficulty, effort, api) {
                        const rates = []
-                       for (let i = 0; i < 100; i++) {
+                       for (let i = 0; i < runs; 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/>`
+                               console.log(`%cNanoPow ${api}`, 'color:green', `Calculate proof-of-work for ${runs} unique send block hashes`)
+                               for (let j = 0; j < size; j++) {
+                                       document.getElementById('status').innerHTML = `SCORING IN PROGRESS. THIS WILL TAKE A LONG TIME. ${i}/${size} ${j}/${runs}<br/>`
                                        const hash = random()
                                        let result = null
                                        const start = performance.now()
                                        try {
-                                               result = await NanoPow.work_generate(hash)
+                                               result = await NanoPow.work_generate(hash, { difficulty, effort, api })
                                        } catch (err) {
                                                document.getElementById('output').innerHTML += `Error: ${err.message}<br/>`
                                                console.error(err)
@@ -199,14 +201,14 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                console.log(results)
                                const { truncatedRate } = results
                                rates.push(truncatedRate)
-                               document.getElementById('output').innerHTML += `Truncated Rate ${i}: ${truncatedRate}<br/>`
+                               document.getElementById('output').innerHTML += `Benchmark ${i + 1} score: ${truncatedRate} wps<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('summary').innerHTML += `work-per-second: ${truncatedHarmonic}<br/>`
                        document.getElementById('status').innerHTML = `SCORING COMPLETE<br/>`
                        console.log('%cSCORING COMPLETE', 'color:orange;font-weight:bold')
                }
@@ -245,14 +247,14 @@ SPDX-License-Identifier: GPL-3.0-or-later
 
                function startTest (event) {
                        event.target.disabled = true
-                       const difficulty = document.getElementById('difficulty')
                        const size = document.getElementById('size')
+                       const difficulty = document.getElementById('difficulty')
                        const effort = document.getElementById('effort')
-                       const isOutputShown = document.getElementById('isOutputShown')
                        const api = document.getElementById('api')
+                       const isOutputShown = document.getElementById('isOutputShown')
                        const isDebug = document.getElementById('isDebug')
                        const isSelfCheck = document.getElementById('isSelfCheck')
-                       run(difficulty.value, +size.value, +effort.value, isOutputShown.checked, api.value, isDebug.checked, isSelfCheck.checked)
+                       run(+size.value, difficulty.value, +effort.value, api.value, isOutputShown.checked, isDebug.checked, isSelfCheck.checked)
                                .then(() => {
                                        event.target.disabled = false
                                        isSelfCheck.checked = false
@@ -261,7 +263,14 @@ SPDX-License-Identifier: GPL-3.0-or-later
 
                function startScore (event) {
                        event.target.disabled = true
-                       score().then(() => event.target.disabled = false)
+                       const runs = document.getElementById('runs')
+                       const size = document.getElementById('size')
+                       const difficulty = document.getElementById('difficulty')
+                       const effort = document.getElementById('effort')
+                       const api = document.getElementById('api')
+                       const isOutputShown = document.getElementById('isOutputShown')
+                       score(+runs.value, +size.value, difficulty.value, +effort.value, api.value, isOutputShown.checked)
+                               .then(() => event.target.disabled = false)
                }
 
                document.getElementById('btnStartTest').addEventListener('click', startTest)
@@ -269,10 +278,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
                document.getElementById('effort').value = Math.max(1, Math.floor(navigator.hardwareConcurrency) / 2)
        </script>
        <style>
-               body{background:black;color:white;}a{color:darkcyan;}input[type=number]{width:5em;}span{margin:0.5em;}
-               label.hex::after{color:grey;content:'0x';display:inline-block;font-size:90%;left:0.5em;position:relative;width:0;}
-               label.hex+input{padding-left:1.5em;}
-               .warning::after{content:'⚠️'}
+               body{background:black;color:white;}a{color:darkcyan;}input[type=number]{width:5em;}
+               div.hex{display:inline-block}
+               div.hex::before{color:grey;content:'0x';display:inline-block;font-size:90%;left:0.5em;position:relative;width:0;}
+               div.hex>input{padding-left:1.5em;}
+               .warning::before{content:'⚠️'}
        </style>
 </head>
 
@@ -285,15 +295,15 @@ SPDX-License-Identifier: GPL-3.0-or-later
        <p>Times below are in milliseconds and are summarized by various averaging methods.</p>
        <p>Level of Effort depends on hardware and does not guarantee faster results.</p>
        <hr />
-       <label for="difficulty" class="hex">Difficulty</label>
-       <input id="difficulty" type="text" value="FFFFFFF800000000" />
-       <hr />
-       <label for="work" class="hex">Validate Work</label>
-       <input id="work" type="text" />
+       <label for="work">Validate Work</label>
+       <div class="hex"><input id="work" type="text" /></div>
        <label for="hash" class="hex">Hash</label>
-       <input id="hash" type="text" />
+       <div class="hex"><input id="hash" type="text" /></div>
        <span id="validation"></span>
        <hr />
+       <h3>Options</h3>
+       <label for="difficulty" class="hex">Difficulty</label>
+       <div class="hex"><input id="difficulty" type="text" value="FFFFFFF800000000" /></div>
        <label for="size">Test Size</label>
        <input id="size" type="number" value="1" autofocus />
        <label for="effort">Effort (1-32)</label>
@@ -307,6 +317,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        <option>CPU</option>
                </select>
        </span>
+       <hr />
+       <h3>Benchmarking</h3>
        <span>
                <label for="isOutputShown">Show output?</label>
                <input id="isOutputShown" type="checkbox" checked />
@@ -321,7 +333,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
        </span>
        <button id="btnStartTest">Go</button>
        <hr />
+       <h3>Scoring</h3>
+       <label for="runs">Score Runs</label>
+       <input id="runs" type="number" value="1" autofocus />
        <button id="btnStartScore">Score ❗</button>
+       <hr />
        <h3 id="status">WAITING</h3>
        <hr />
        <pre id="summary"></pre>