Verifying Correctness While Measuring an Optimization

A comparison needs to confirm that each version computes the promised result. Shortcuts omitting meaningful work can look fast.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a report change
  2. Check selected effects
  3. Compare behavior before comparing time
  4. Consider correctness under concurrency too

Trace a report change

A quicker aggregation accidentally drops the final row. Comparing only duration would praise the change. An independently expected output catches the difference. See regression tests.

Check selected effects

The same result value may still hide missing output or extra writes if those effects are promised. Use postconditions to choose verification beyond a timing outcome.[1]

Compare behavior before comparing time

A faster filtering algorithm might skip records with zero values because it treats zero like absence. Include zero and null together in a fixture and compare exact accepted identities. Once both versions meet the same contract, measure their work under the same conditions. See missing, empty and zero values.

Inputs: present zero, present positive, absent
Baseline and candidate must agree under the contract
Compare result IDs, values and order if promised
Time verified executions

Consider correctness under concurrency too

Some optimizations reuse cached or shared state. Test after updates and under mixed requests when relevant. Measure the normal entry point as well as the isolated operation.

References

  1. Google, Site Reliability Engineering ↩