]> zoso.dev Git - nano-pow.git/commitdiff
Initial move to webpage for test output.
authorChris Duncan <chris@zoso.dev>
Sat, 11 Jan 2025 04:00:06 +0000 (20:00 -0800)
committerChris Duncan <chris@zoso.dev>
Sat, 11 Jan 2025 04:00:06 +0000 (20:00 -0800)
test-tools.mjs [moved from test/CONFIG.mjs with 98% similarity]
test.html [new file with mode: 0644]
test/index.html [deleted file]
test/test.mjs [deleted file]

similarity index 98%
rename from test/CONFIG.mjs
rename to test-tools.mjs
index 7afb956f32ef1fcc3d79894e09942281a3ac21d9..65c5c78ac0cd01dc1da59be35c9bb676c3327b61 100644 (file)
@@ -227,3 +227,5 @@ export const assert = {
                }
        }
 }
+
+globalThis.TOOLING ??=  { assert, average, print, random, skip, suite, test }
diff --git a/test.html b/test.html
new file mode 100644 (file)
index 0000000..0cf6041
--- /dev/null
+++ b/test.html
@@ -0,0 +1,80 @@
+<!--
+SPDX-FileCopyrightText: 2025 2025 Chris Duncan <chris@zoso.dev>
+SPDX-License-Identifier: GPL-3.0-or-later
+-->
+
+<!DOCTYPE html>
+
+<head>
+       <link rel="icon" href="./favicon.ico">
+       <script type="module" src="./test-tools.mjs"></script>
+       <script type="module" src="../dist/global.min.js"></script>
+       <script type="module" src="https://cdn.jsdelivr.net/npm/nano-webgl-pow@1.1.1/nano-webgl-pow.js"></script>
+       <script type="module">
+               const { assert, average, print, random, skip, suite, test } = TOOLING
+               const { NanoPowGl, NanoPowGpu } = NanoPow
+
+               await suite('Block performance', async () => {
+                       const COUNT = 0xf
+
+                       await test(`NanoPowGpu: Calculate proof-of-work for ${COUNT} unique send block hashes`, async () => {
+                               const times = []
+                               for (let i = 0; i < COUNT; i++) {
+                                       const hash = random()
+                                       const start = performance.now()
+                                       const work = await NanoPowGpu.search(hash)
+                                       const end = performance.now()
+                                       times.push(end - start)
+                                       console.log(`${work} (${end - start} ms) ${hash}`)
+                                       document.getElementById('output').innerHTML += `${hash} <${work}> (${end - start} ms)<br/>`
+                               }
+                               print(times)
+                       })
+
+                       await test(`NanoPowGl: Calculate proof-of-work for ${COUNT} unique send block hashes`, async () => {
+                               const times = []
+                               for (let i = 0; i < COUNT; i++) {
+                                       const hash = random()
+                                       const start = performance.now()
+                                       const work = await NanoPowGl.search(hash)
+                                       const end = performance.now()
+                                       times.push(end - start)
+                                       console.log(`${work} (${end - start} ms) ${hash}`)
+                               }
+                               print(times)
+                       })
+
+                       await test(`nano-webgl-pow: Calculate proof-of-work for ${COUNT} unique send block hashes`, async () => {
+                               //@ts-expect-error
+                               window.NanoWebglPow.width = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency))
+                               //@ts-expect-error
+                               window.NanoWebglPow.height = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency))
+                               const times = []
+                               for (let i = 0; i < COUNT; i++) {
+                                       const hash = random()
+                                       const start = performance.now()
+                                       const work = await new Promise(resolve => {
+                                               //@ts-expect-error
+                                               window.NanoWebglPow(hash, resolve, undefined, '0xFFFFFFF8')
+                                       })
+                                       const end = performance.now()
+                                       times.push(end - start)
+                                       console.log(`${work} (${end - start} ms)`)
+                               }
+                               print(times)
+                       })
+               })
+
+               console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold')
+
+
+       </script>
+       <style>body{background:black;color:white;}</style>
+</head>
+
+<body>
+       <h1>nano-pow</h1>
+       <div id="output"></pre>
+       </body>
+
+       </html>
diff --git a/test/index.html b/test/index.html
deleted file mode 100644 (file)
index 3cb8c5d..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<!--
-SPDX-FileCopyrightText: 2025 2025 Chris Duncan <chris@zoso.dev>
-SPDX-License-Identifier: GPL-3.0-or-later
--->
-
-<!DOCTYPE html>
-
-<head>
-       <link rel="icon" href="./favicon.ico">
-       <script type="module" src="./test.mjs"></script>
-       <script type="module" src="https://cdn.jsdelivr.net/npm/nano-webgl-pow@1.1.1/nano-webgl-pow.js"></script>
-       <style>body{background:black;}</style>
-</head>
-
-<body></body>
-
-</html>
diff --git a/test/test.mjs b/test/test.mjs
deleted file mode 100644 (file)
index 41b1d93..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-// SPDX-FileCopyrightText: 20245Chris Duncan <chris@zoso.dev>
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-'use strict'
-
-import { assert, average, print, random, skip, suite, test } from './CONFIG.mjs'
-import { NanoPowGl, NanoPowGpu } from '../dist/main.min.js'
-
-await suite('Block performance', async () => {
-       const COUNT = 0xf
-
-       await test(`NanoPowGpu: Calculate proof-of-work for ${COUNT} unique send block hashes`, async () => {
-               const times = []
-               for (let i = 0; i < COUNT; i++) {
-                       const hash = random()
-                       const start = performance.now()
-                       const work = await NanoPowGpu.search(hash)
-                       const end = performance.now()
-                       times.push(end - start)
-                       console.log(`${work} (${end - start} ms) ${hash}`)
-               }
-               print(times)
-       })
-
-       await test(`NanoPowGl: Calculate proof-of-work for ${COUNT} unique send block hashes`, async () => {
-               const times = []
-               for (let i = 0; i < COUNT; i++) {
-                       const hash = random()
-                       const start = performance.now()
-                       const work = await NanoPowGl.search(hash)
-                       const end = performance.now()
-                       times.push(end - start)
-                       console.log(`${work} (${end - start} ms) ${hash}`)
-               }
-               print(times)
-       })
-
-       await test(`nano-webgl-pow: Calculate proof-of-work for ${COUNT} unique send block hashes`, async () => {
-               //@ts-expect-error
-               window.NanoWebglPow.width = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency))
-               //@ts-expect-error
-               window.NanoWebglPow.height = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency))
-               const times = []
-               for (let i = 0; i < COUNT; i++) {
-                       const hash = random()
-                       const start = performance.now()
-                       const work = await new Promise(resolve => {
-                               //@ts-expect-error
-                               window.NanoWebglPow(hash, resolve, undefined, '0xFFFFFFF8')
-                       })
-                       const end = performance.now()
-                       times.push(end - start)
-                       console.log(`${work} (${end - start} ms)`)
-               }
-               print(times)
-       })
-})
-
-console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold')
-