}
}
- 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) {
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)
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')
}
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
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)
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>
<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>
<option>CPU</option>
</select>
</span>
+ <hr />
+ <h3>Benchmarking</h3>
<span>
<label for="isOutputShown">Show output?</label>
<input id="isOutputShown" type="checkbox" checked />
</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>