-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,55 @@ | ||
import mandelbrot from "./mandelbrot.tal"; | ||
import Uxn from "../uxn"; | ||
import suite from "./suite"; | ||
|
||
const DEV_OFFSET = 0x10200; | ||
const PROGRAM_OFFSET = 0x100; | ||
|
||
document.body.innerHTML = ` | ||
<h1>Uxn.wasm Benchmarks</h1> | ||
<div> | ||
<button id="startButton">Start</button> | ||
<table> | ||
<tr id="mandelbrotResults"></tr> | ||
<table id="results"> | ||
</table> | ||
</div> | ||
`; | ||
const startButtonEl = document.getElementById("startButton"); | ||
const mandelbrotResultsEl = document.getElementById("mandelbrotResults"); | ||
const resultsEl = document.getElementById("results"); | ||
|
||
function runMandelbrot(uxn) { | ||
uxn.load(mandelbrot); | ||
uxn.eval(PROGRAM_OFFSET); | ||
} | ||
startButtonEl.onclick = async () => { | ||
startButtonEl.disabled = true; | ||
resultsEl.replaceChildren(); | ||
for (const b of suite) { | ||
const trEl = document.createElement("table"); | ||
resultsEl.appendChild(trEl); | ||
const thEl = document.createElement("th"); | ||
thEl.appendChild(document.createTextNode(b.name)); | ||
trEl.appendChild(thEl); | ||
|
||
async function runMandelbrotBenchmark() { | ||
try { | ||
startButtonEl.disabled = true; | ||
const uxn = new Uxn(); | ||
await uxn.init({ | ||
deo: () => {}, | ||
dei: (port) => { | ||
return uxn.ram[DEV_OFFSET + port]; | ||
}, | ||
}); | ||
mandelbrotResultsEl.innerHTML = "<th>Mandelbrot</th>"; | ||
|
||
for (let i = 0; i < 5; i++) { | ||
const el = document.createElement("td"); | ||
mandelbrotResultsEl.appendChild(el); | ||
el.appendChild(document.createTextNode("⌛️")); | ||
const t1 = performance.now(); | ||
runMandelbrot(uxn); | ||
const t2 = performance.now(); | ||
el.innerHTML = ((t2 - t1) / 1000.0).toFixed(2) + "s"; | ||
const tdEl = document.createElement("td"); | ||
const valueEl = document.createTextNode("⌛️"); | ||
tdEl.appendChild(valueEl); | ||
trEl.appendChild(tdEl); | ||
let value; | ||
|
||
try { | ||
const t1 = performance.now(); | ||
b.run(uxn); | ||
const t2 = performance.now(); | ||
value = ((t2 - t1) / 1000.0).toFixed(2) + "s"; | ||
} catch (e) { | ||
console.error(e); | ||
value = "error: " + e; | ||
} | ||
tdEl.replaceChild(document.createTextNode(value), valueEl); | ||
} | ||
} finally { | ||
startButtonEl.disabled = false; | ||
} | ||
} | ||
|
||
startButtonEl.onclick = () => { | ||
runMandelbrotBenchmark(); | ||
startButtonEl.disabled = false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const suite = require("./suite").default; | ||
const Uxn = require("../uxn"); | ||
|
||
const DEV_OFFSET = 0x10200; | ||
|
||
(async () => { | ||
const uxn = new Uxn(); | ||
await uxn.init({ | ||
deo: () => {}, | ||
dei: (port) => { | ||
return uxn.ram[DEV_OFFSET + port]; | ||
}, | ||
}); | ||
for (const b of suite) { | ||
console.log(b.name); | ||
for (let i = 0; i < 5; i++) { | ||
let value; | ||
const t1 = performance.now(); | ||
b.run(uxn); | ||
const t2 = performance.now(); | ||
value = ((t2 - t1) / 1000.0).toFixed(2) + "s"; | ||
console.log(` run ${i + 1}: ` + value); | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import mandelbrot from "./mandelbrot.tal"; | ||
|
||
const PROGRAM_OFFSET = 0x100; | ||
|
||
export default [ | ||
{ | ||
name: "mandelbrot", | ||
run: (uxn) => { | ||
uxn.load(mandelbrot); | ||
uxn.eval(PROGRAM_OFFSET); | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters