#!/usr/bin/env bash # SPDX-License-Identifier: MIT # The wasm32 build of a base revision against the working tree's, under Node, alternately: # ROUNDS rounds of scripts/wasm_bench.mjs (STEPS steps, one run a workload), each side's # best per workload. Both sides use the working tree's wasm_bench.mjs and wasm.rs # (copied into the base worktree, target/ab-base), so the harness is the same. # scripts/ab-wasm.sh [BASE_REV] env: ROUNDS (4), STEPS (10,000,000), CPU (30), # FEATURES_B, ENV_B (as ab.sh; ENV_B is not used here) set -euo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) source "$ROOT/scripts/env.sh" BASE=${1:-HEAD}; ROUNDS=${ROUNDS:-4}; STEPS=${STEPS:-10000000}; CPU=${CPU:-30} rev=$(git -C "$ROOT" rev-parse --short "$BASE") B="$ROOT/target/ab-base" [ -d "$B" ] || git -C "$ROOT" worktree add -q --detach "$B" "$rev" git -C "$B" checkout -q -f --detach "$rev" cp "$ROOT/src/wasm.rs" "$B/src/wasm.rs" wasm() { # tree features -> path PATH="$STABLE:$PATH" CARGO_TARGET_DIR="$1/target/wasm" nice -n 19 cargo build --release -q -j 2 --lib \ --no-default-features ${2:+--features "$2"} --target wasm32-unknown-unknown --manifest-path "$1/Cargo.toml" >&2 echo "$1/target/wasm/wasm32-unknown-unknown/release/sh2.wasm" } a=$(wasm "$B" ""); b=$(wasm "$ROOT" "${FEATURES_B:-}") echo "wasm: base $rev vs working tree; $ROUNDS rounds, $STEPS steps, cpu $CPU, load $(cut -d' ' -f1-3 /proc/loadavg)" for r in $(seq "$ROUNDS"); do for side in a b; do bin=$a; [ $side = b ] && bin=$b taskset -c "$CPU" node "$ROOT/scripts/wasm_bench.mjs" "$bin" "$STEPS" 1 | sed "s/^/$side /" done done | python3 -c " import re, sys, collections best = collections.defaultdict(float) for line in sys.stdin: side, rest = line.split(' ', 1) m = re.search(r'\): (.*?), \d+ steps .* best (\d+)', rest) best[(side, m.group(1))] = max(best[(side, m.group(1))], float(m.group(2))) import math ratios = [] for name in sorted({k[1] for k in best}): a, b = best[('a', name)], best[('b', name)] ratios.append(b / a) print(f'{name}: A {a/1e6:.2f} M/s, B {b/1e6:.2f} M/s, x{b/a:.3f}') print(f'overall x{math.exp(sum(map(math.log, ratios))/len(ratios)):.3f}') "