Skip to main content

Checkpoint: measure, don't guess

Challenge on lesson: Checkpoint: Measure, Don't Guess

Inside Solution, implement the harness and use it: 1. static long sumTo(int n) — plain loop sum 1..n, return the sum (the workload). 2. static long measureSumMicros(int n, int rounds) — warm up 2_000 untimed runs, then time rounds runs of sumTo(n) in MICROS; return the MEDIAN. Every run's result must be verified against n*(n+1)/2 (consume it). 3. static boolean fasterWithinEpsilon(long aMicros, long bMicros, double epsFrac) — true iff a < b AND the gap (b - a) exceeds epsFrac * b (b is the slower baseline; a only wins beyond the epsilon). 4. static String claim(long aMicros, long bMicros) — return "faster" if fasterWithinEpsilon(a, b, 0.10), "slower" if fasterWithinEpsilon(b, a, 0.10), else "no measured difference".

Difficulty: advanced

Back to lesson: Checkpoint: Measure, Don't Guess