01-benchmark-harness built the measurement tool, this question puts it to real use: take a genuine baseline implementation (math-matrix-multiplication's from-scratch, doubly-nested-loop matmul), apply ONE concrete optimization (swap in NumPy's vectorized @ operator), and measure whether it's ACTUALLY faster, while never trusting a speedup number until the optimized version's OUTPUT has also been checked against the baseline.
Implement optimized_matmul (the optimization itself), verify_optimization_correctness (checking the optimization didn't change the answer), and benchmark_optimization, tying both the speed measurement and the correctness check together into one result.
optimized_matmul(a, b) returns a @ b.verify_optimization_correctness(a, b) returns True exactly when matmul_from_scratch(a, b) and optimized_matmul(a, b) agree (via np.allclose).benchmark_optimization(a, b, num_runs=5) times both implementations with 01-benchmark-harness's time_function, and returns a dict with "baseline"/"optimized" statistics, a "speedup_factor" (baseline median / optimized median), and "correctness_verified".Open one at a time. Each gives away a little more than the last.
Use MEDIAN (not mean) timing for speedup_factor: a median is more robust to the occasional unusually slow measurement (a stray OS scheduling hiccup) than a mean is.
benchmark_optimization should call time_function(lambda: matmul_from_scratch(a, b), num_runs=num_runs) and time_function(lambda: optimized_matmul(a, b), num_runs=num_runs): wrapping each call in a lambda is what lets time_function's zero-argument-callable contract work with functions that actually need arguments.
No results yet
Run your code to check it against the examples, or submit to run every test.