<head>
<link rel="icon" href="#">
- <script type="module">
- try {
- const { hostname, port } = new URL(window.location)
- let NanoPow, Cache, stats
- if (port && hostname === '127.0.0.1') {
- NanoPow = await import('../dist/index.js')
- } else {
- try {
- NanoPow = await import('https://unpkg.com/nano-pow@5.2/dist/index.js')
- } catch (err) {
- console.warn(err)
- try {
- NanoPow = await import('https://cdn.jsdelivr.net/npm/nano-pow@5.2/dist/index.js')
- } catch (err) {
- throw new Error(`Failed to load NanoPow ${err}`)
- }
- }
- }
-
- if (port && hostname === '127.0.0.1') {
- ({ Cache, stats } = await import('../dist/utils/index.js'))
- } else {
- try {
- ({ Cache, stats } = await import('https://unpkg.com/nano-pow@5.2/dist/utils/index.js'))
- } catch (err) {
- console.warn(err)
- try {
- ({ Cache, stats } = await import('https://cdn.jsdelivr.net/npm/nano-pow@5.2/dist/utils/index.js'))
- } catch (err) {
- throw new Error(`Failed to load NanoPow utilities ${err}`)
- }
+ <script type="importmap">
+ {
+ "imports": {
+ "nano-pow": "https://unpkg.com/nano-pow@5.2.0/dist/index.js",
+ "nano-pow/utils": "https://unpkg.com/nano-pow@5.2.0/dist/utils/index.js"
+ },
+ "scopes": {
+ "/test/": {
+ "nano-pow": "../dist/index.js",
+ "nano-pow/utils": "../dist/utils/index.js"
}
}
+ }
+ </script>
+ <script type="module">
+ import { NanoPow } from 'nano-pow'
+ import { Cache, stats } from 'nano-pow/utils'
+ try {
const glSize = (canvas => {
const gl = canvas.getContext('webgl2')
const MAX_VIEWPORT_DIMS = gl?.getParameter(gl.MAX_VIEWPORT_DIMS) ?? [0x1000, 0x1000]
return gl?.drawingBufferHeight < gl?.drawingBufferWidth ? gl?.drawingBufferHeight : gl?.drawingBufferWidth
})(new OffscreenCanvas(0, 0))
- function random (size = 64) {
+ function random(size = 64) {
let hex = ''
while (hex.length < size) {
hex += crypto.randomUUID().replace(/-.*-/g, '')
return hex.slice(0, size)
}
- function average (times, type, effort) {
+ function average(times, type, effort) {
const averages = stats(times)
const title = type === 'WebGPU'
? `NanoPow (${type}) | Effort: ${effort} | Dispatch: ${(effort << 8) << 1} | Threads: ${64 * (effort << 8) << 1}`
}
}
- async function run (size, difficulty, effort, api, isOutputShown, isDebug, isSelfCheck) {
+ 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', debug: isDebug })
const type = api
console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold')
}
- async function score (runs, size, difficulty, effort, api) {
+ async function score(runs, size, difficulty, effort, api) {
console.log(`%cNanoPow ${api}`, 'color:green', `Calculate truncated harmonic mean of the truncated arithmetic rate across ${runs} runs of ${size} samples.`)
const rates = []
for (let i = 0; i < runs; i++) {
console.log('%cSCORING COMPLETE', 'color:orange;font-weight:bold')
}
- async function execute (size, difficulty, effort, api, isOutputShown = false, debug = false) {
+ async function execute(size, difficulty, effort, api, isOutputShown = false, debug = false) {
Cache.clear()
const output = document.getElementById('output')
const status = document.getElementById('status')
return times
}
- function startValidation (event) {
+ function startValidation(event) {
const difficulty = document.getElementById('difficulty')?.value
const work = document.getElementById('work')?.value
const hash = document.getElementById('hash')?.value
document.getElementById('hash').addEventListener('input', startValidation)
document.getElementById('api').addEventListener('input', startValidation)
- function startTest (event) {
+ function startTest(event) {
event.target.disabled = true
const size = document.getElementById('size')
const difficulty = document.getElementById('difficulty')
})
}
- function startScore (event) {
+ function startScore(event) {
event.target.disabled = true
const runs = document.getElementById('runs')
const size = document.getElementById('size')