n++
if (Pow.#gl == null) throw new Error('WebGL 2 is required')
if (Pow.#query == null) throw new Error('WebGL 2 is required to run queries')
- performance.mark('start')
crypto.getRandomValues(work)
Pow.#gl.clear(Pow.#gl.COLOR_BUFFER_BIT)
// A valid nonce was found
readBackResult()
} else {
- performance.mark('end')
- frameTimes.push(performance.measure('draw', 'start', 'end').duration)
- performance.clearMarks()
- performance.clearMeasures()
// No valid nonce found, start the next draw call
requestAnimationFrame(draw)
}
// Check the pixels for any success
for (let i = 0; i < Pow.#pixels.length; i += 4) {
if (Pow.#pixels[i] !== 0) {
- performance.mark('end')
- frameTimes.push(performance.measure('draw', 'start', 'end').duration)
- performance.clearMarks()
- console.log(`average frame time: ${(frameTimes.reduce((a, b) => a + b)) / frameTimes.length} ms`)
- console.log(`frames calculated: ${n}`)
let sum = 0, reciprocals = 0, product = 1, count = frameTimes.length
for (let i = 0; i < count; i++) {
sum += frameTimes[i]
reciprocals += 1 / frameTimes[i]
product *= frameTimes[i]
}
- console.log(`Total: ${sum} ms`)
- console.log(`Average: ${sum / count} ms`)
- console.log(`Harmonic: ${count / reciprocals} ms`)
- console.log(`Geometric: ${Math.pow(product, 1 / count)} ms`)
const hex = Pow.#hexify(work.subarray(4, 8)) + Pow.#hexify([
Pow.#pixels[i + 2],
Pow.#pixels[i + 3],