diff --git a/examples/wasm/parallel_assets.html b/examples/wasm/parallel_assets.html new file mode 100644 index 00000000..4b054c36 --- /dev/null +++ b/examples/wasm/parallel_assets.html @@ -0,0 +1,190 @@ + + + + + Wickra WASM — parallel assets + + + +

Wickra WASM — parallel assets

+

+ Builds a synthetic (assets, bars) panel, runs a serial + baseline on the main thread, then dispatches the same workload to a + pool of Workers — each loading its own copy of the + WebAssembly module — and reports the speedup. The browser counterpart + of examples/node/parallel_assets.js and + examples/rust/src/bin/parallel_assets.rs. +

+ +

+ + + + + +

+ +
+

Serial

+

Parallel

+

Speedup

+
+ +

Loading WASM module…

+
+ + + + diff --git a/examples/wasm/parallel_worker.js b/examples/wasm/parallel_worker.js new file mode 100644 index 00000000..fc367d51 --- /dev/null +++ b/examples/wasm/parallel_worker.js @@ -0,0 +1,27 @@ +// Module worker for `examples/wasm/parallel_assets.html`. Each worker loads +// its own copy of the WebAssembly module, then processes the slice of the +// (assets, bars) panel its parent dispatches via `postMessage` and sends +// the per-asset "last non-null indicator value" back. + +import init, { SMA, RSI } from "../../bindings/wasm/pkg/wickra_wasm.js"; + +const ready = init(); + +self.addEventListener("message", async (event) => { + await ready; + const { panelSlice, indicator } = event.data; + + const results = new Array(panelSlice.length); + for (let i = 0; i < panelSlice.length; i++) { + const prices = panelSlice[i]; + const ind = indicator === "sma" ? new SMA(14) : new RSI(14); + let last = null; + for (let j = 0; j < prices.length; j++) { + const v = ind.update(prices[j]); + if (v !== null) last = v; + } + results[i] = last; + } + + self.postMessage(results); +});