import { assert, average, skip, suite, test } from '#GLOBALS.mjs'
import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js'
-import { SendBlock } from '#dist/main.js'
+import { PowGpu, SendBlock } from '#dist/main.js'
import 'nano-webgl-pow'
await suite('Block performance', async () => {
- const COUNT = 0x1
+ const COUNT = 0x10
- await test(`Customized PoW: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => {
+ await test(`Customized PoW: Time to calculate proof-of-work for a block hash ${COUNT} times`, async () => {
+ const times = []
+ const hashes = [
+ NANO_TEST_VECTORS.PRIVATE_0,
+ NANO_TEST_VECTORS.PRIVATE_1,
+ NANO_TEST_VECTORS.PRIVATE_2,
+ NANO_TEST_VECTORS.PUBLIC_0,
+ NANO_TEST_VECTORS.PUBLIC_1,
+ NANO_TEST_VECTORS.PUBLIC_2
+ ]
+ for (let i = 0; i < 6; i++) {
+ const start = performance.now()
+ const work = await PowGpu.find(hashes[i])
+ const end = performance.now()
+ times.push(end - start)
+ console.log(`${work} (${end - start} ms) ${hashes[i]}`)
+ }
+ const { total, arithmetic, harmonic, geometric } = average(times)
+ console.log(`Total: ${total} ms`)
+ console.log(`Average: ${arithmetic} ms`)
+ console.log(`Harmonic: ${harmonic} ms`)
+ console.log(`Geometric: ${geometric} ms`)
+ })
+
+ await skip(`Customized PoW: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => {
const times = []
const block = new SendBlock(
NANO_TEST_VECTORS.SEND_BLOCK.account,
await block.pow()
const end = performance.now()
times.push(end - start)
- console.log(`${block.work} (${end - start} ms)`)
+ console.log(`${block.work} (${end - start} ms) ${block.previous}`)
+ block.previous = 'BB569136FA05F8CBF65CEF2EDE368475B289C4477342976556BA4C0DDF216E45'
}
const { total, arithmetic, harmonic, geometric } = average(times)
console.log(`Total: ${total} ms`)