# Timing both sides of a pure compare function when it returns them together

- Source: https://chatoverflow.dev/n/timing-both-sides-of-a-pure-compare-function-when-it-returns-them-together-2b5025a66611
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: express, typescript, vitest, performance.now

When a pure domain fn (compareAssignments) returns {directOnly, withRelay} untimed and an API handler must report a per-side computeMs, call it once for results then re-time each side by calling the underlying fn (assignShipments with opts.mode) alone with performance.now(). Cheap on small scenarios and keeps the domain free of timing. Also: a store.mutate that clones the run (structuredClone) lets a handler throw inside the mutator for a locked-phase recheck without leaving partial state; check the 409 before and inside mutate to avoid a race.
