actual tests and wasm-opt

This commit is contained in:
Toshit Chawda 2024-01-11 22:45:05 -08:00
parent 7bb39ae069
commit 6e973a98d5
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
3 changed files with 39 additions and 9 deletions

View file

@ -9,5 +9,5 @@
### Client
1. Make sure you have the `wasm32-unknown-unknown` target installed, `wasm-bindgen` executable installed, and `bash`, `python3` packages (`python3` is used for `http.server` module)
2. Run `bash build.sh` to build and start a webserver
1. Make sure you have the `wasm32-unknown-unknown` target installed, `wasm-bindgen` executable installed (and optionally `wasm-opt`), and `bash`, `python3` packages (`python3` is used for `http.server` module)
2. Run `bash build.sh` to build without wasm-opt and start a webserver, add any argument to call wasm-opt

View file

@ -6,5 +6,9 @@ rm -rf out/ || true
mkdir out/
cargo build --target wasm32-unknown-unknown --release
wasm-bindgen --weak-refs --no-typescript --target no-modules --out-dir out/ ../target/wasm32-unknown-unknown/release/wstcp_client.wasm
if [[ "$#" > 0 ]]; then
mv out/wstcp_client_bg.wasm out/wstcp_client_unoptimized.wasm
wasm-opt -O4 out/wstcp_client_unoptimized.wasm -o out/wstcp_client_bg.wasm
fi
cp -r src/web/* out/
(cd out; python3 -m http.server)

View file

@ -4,17 +4,43 @@
"color:red;font-size:2rem;font-weight:bold"
);
await wasm_bindgen("./wstcp_client_bg.wasm");
const tconn0 = performance.now();
// args: websocket url, user agent, redirect limit
let wstcp = await new wasm_bindgen.WsTcp("wss://localhost:4000", navigator.userAgent, 10);
const tconn1 = performance.now();
console.warn(`conn establish took ${tconn1 - tconn0} ms or ${(tconn1 - tconn0) / 1000} s`);
const t0 = performance.now();
let resp = await wstcp.fetch("http://httpbin.org/redirect/11");
const t1 = performance.now();
console.warn(resp);
console.warn(Object.fromEntries(resp.headers));
console.warn(await resp.text());
console.warn(`mux 1 took ${t1 - t0} ms or ${(t1 - t0) / 1000} s`);
const test_mux = async (url) => {
const t0 = performance.now();
await wstcp.fetch(url);
const t1 = performance.now();
return t1 - t0;
};
const test_native = async (url) => {
const t0 = performance.now();
await fetch(url);
const t1 = performance.now();
return t1 - t0;
};
const num_tests = 10;
let total_mux = 0;
for (const _ of Array(num_tests).keys()) {
total_mux += await test_mux("https://httpbin.org/get");
}
total_mux = total_mux / num_tests;
let total_native = 0;
for (const _ of Array(num_tests).keys()) {
total_native += await test_native("https://httpbin.org/get");
}
total_native = total_native / num_tests;
console.warn(`avg mux (10) took ${total_mux} ms or ${total_mux / 1000} s`);
console.warn(`avg native (10) took ${total_native} ms or ${total_native / 1000} s`);
console.warn(`mux - native: ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
alert("you can open console now");
})();