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
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>
<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>