ac-bench
Explanation

Explanation

Nested conditions specialise, they do not group

A condition may declare cases and nested conditions. Nesting looks like grouping, and is not — the one rule a suite's author cannot infer from the API.

A condition may declare cases and nested conditions. Nesting looks like grouping — and is not. This is the one rule of @ac-bench a suite’s author cannot infer from the API.

The rule

Only a condition with no nested condition of its own is executed: a fork unit. It runs its own cases and every case its enclosing conditions declare, under the enclosing conditions’ hooks (beforeAll, onBegin, …) from the outside in.

parse.bench.ts
durationCondition("parse", () => {
  durationCase("small", () => parse(small));
  durationCase("large", () => parse(large));

  durationCondition("cold cache", () => {
    beforeAll(() => clearCache());
  });
  durationCondition("warm cache", () => {
    beforeAll(() => warmCache());
  });
});

This measures small and large twice: once in parse > cold cache, once in parse > warm cache. parse itself never runs on its own, because it has nested conditions.

Why specialisation

The point of writing a hierarchy is to measure the same cases under different setups: a cache state, a data size, an option. Grouping would need each inner condition to repeat the cases; specialisation declares them once, and each leaf is a context they are measured in. A comparison between the leaves is a comparison of contexts on identical cases — what the hierarchy was for.

Consequences

  • A condition that declares cases and nested conditions never measures its cases alone. To measure them without a specialisation too, add a leaf with no hooks: durationCondition("default", () => {}).
  • Hooks run outermost first on the way in and innermost first on the way out, once per fork unit, in the fork unit’s own child.
  • A case’s key, its baseline identity and its gates’ references are condition > … > case along the leaf’s path: the same case under two leaves is two cases, and a gate in an enclosing condition applies in each leaf.
  • Titles join outermost first (parse > warm cache), as tables, archives and --filter show them.