Fix benchmark status + more WASM hell

also cors is dum
This commit is contained in:
Tyler Beckman 2023-12-11 00:16:11 -07:00
parent 0efc64a4ac
commit 97e901ee19
Signed by: Ty
GPG key ID: 2813440C772555A4
4 changed files with 54 additions and 10 deletions

View file

@ -147,7 +147,7 @@ async fn main() {
let end = Instant::now();
timings.push(end - start);
print!("\r{:.2}%", ((i - warmup) as f32 / n as f32) * 100.0);
print!("\r{:.2}%", (i as f32 / (n + warmup) as f32) * 100.0);
let _ = std::io::stdout().flush();
}
timings.drain(..=(warmup as usize));

View file

@ -10,5 +10,5 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
wasm-bindgen = "0.2.84"
wasm-bindgen-futures = "0.4.39"
console_error_panic_hook = { version = "0.1.7", optional = true }
console_error_panic_hook = { version = "0.1.7" }
advent = { path = "../lib" }

View file

@ -1,12 +1,49 @@
<!DOCTYPE HTML>
<html>
<head>
<script>
WebAssembly.instantiateStreaming(fetch("simple.wasm")).then(
(results) => {
console.log(results);
},
);
<script type="module">
import init, * as advent from './pkg/advent_wasm.js';
init(); // Import advent lib and initialize wasm
document.getElementById("set-session-token").onclick = () => {
localStorage.setItem("auth", document.getElementById("session-token").value)
}
document.getElementById("calculate").onclick = async () => {
const auth = localStorage.getItem("auth");
const input = document.getElementById("input").value;
[...document.getElementById("days").children].map(async element => {
const day = element.id[3];
document.getElementById("day" + day).innerHTML = `Day ${day}: ${advent.solve(day, 1, input)}; ${advent.solve(day, 2, input)}`;
})
}
</script>
</head>
<body>
<label for="session-token">Token: </label>
<input id="session-token" type="text" />
<input id="set-session-token" type="button" value="Save" />
<br>
<br>
<label for="input">Input: </label>
<textarea id="input" rows="4" cols="50"></textarea>
<br>
<br>
<input id="calculate" type="button" value="Calculate all" />
<div id="days">
<p id="day1">Day 1: </p>
<p id="day2">Day 2: </p>
<p id="day3">Day 3: </p>
<p id="day4">Day 4: </p>
<p id="day5">Day 5: </p>
<p id="day6">Day 6: </p>
<p id="day7">Day 7: </p>
<p id="day8">Day 8: </p>
<p id="day9">Day 9: </p>
<p id="day10">Day 10: </p>
<p id="day11">Day 11: </p>
</div>
</body>
</html>

View file

@ -1,6 +1,13 @@
use wasm_bindgen::prelude::*;
// #[wasm_bindgen]
// extern "C" {
// fn alert(s: &str);
// }
#[wasm_bindgen]
pub async fn solve(day: u8, part: u8, auth: String) -> String {
advent::get_day(day, advent::fetcher::fetch_input(auth, day).await).solve(part, false)
pub fn solve(day: u8, part: u8, input: String) -> String {
console_error_panic_hook::set_once();
advent::get_day(day, input).solve(part, false)
}