Master the fundamental concepts of profiling & measurement through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksDead-code elimination, constant folding, comparing debug vs release builds, and measuring only one iteration are the classic ways microbenchmarks lie. LLVM and GCC will delete loops whose results are unused. Turbo Boost makes the first timed run faster than the tenth unless you pin frequency or run long enough.
Always consume results. Match compiler flags across A/B tests. Warm up branch predictors and caches. Run on idle hardware or pin cores.
cLoading…
-O0 against -O3 and call it an optimizationuptime and load averageobjdump -d when numbers look impossibleKeep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will identify at least three benchmarking mistakes in provided snippets and fix them. This exercise asks you to demonstrate one pitfall (such as DCE) and show corrected timing.
Most wrong benchmark numbers come from a handful of mistakes. The optimiser deletes work whose result is unused, or precomputes work whose inputs are constants. The timed region is too short for the timer's resolution. Setup code is timed along with the work. The first, cold iteration is included. The machine is noisy between runs. Write a benchmark linter: given a description of a measurement, report every pitfall that applies and correct the number where possible.
cLoading…
Lines may be indented, and each end prints that benchmark's report.
result unused.inputs constant.The report starts with the measured ns per iteration (2 decimals), then one line per problem, then N problem(s) found or looks sound. All numbers are rounded half up. Missing iterations or elapsed prints need iterations and elapsed, an unrecognised key prints NAME: unknown key KEY, and a malformed line prints NAME: bad line: TEXT.
cLoading…
Input:
cLoading…
Output:
cLoading…
elapsed * 4 < iterations * ops).Hidden tests cover a clean benchmark, borderline values exactly at each threshold (which do not trigger), setup larger than the elapsed time, runs given as max then min, a benchmark missing required fields, and unknown keys.