4 Performance
The compiled book tests were run with ambKanren and the stream-based implementation in miniKanren-typed, using the same association-list substitutions, ground-data shortcut and non-search definitions. The first edition includes chapters 1–10 (254 checks); the second includes chapters 1–9 and arithmetic (285 checks). Both use the same source test files and exact assertions, with no answer-order exceptions.
Each implementation was run three times in a fresh process, strictly alternating streams and amb within each edition. The CPU table shows the median (minimum–maximum) in seconds; the allocation table shows rounded medians of cumulative allocations in decimal GB (10^9 bytes). The ratio is amb’s CPU median divided by the stream implementation’s median.
edition |
| streams: CPU s |
| amb: CPU s |
| ratio |
TRS1 |
| 16.22 (15.81–16.77) |
| 28.84 (28.26–31.28) |
| 1.78 |
TRS2 |
| 14.07 (13.10–15.01) |
| 18.90 (17.88–19.76) |
| 1.34 |
edition |
| streams: allocated GB |
| amb: allocated GB |
TRS1 |
| 2.72 |
| 26.72 |
TRS2 |
| 6.10 |
| 19.39 |
These measurements used Racket 9.3 CS on Linux x86-64, an Intel Xeon Platinum 8573C container with nine visible CPUs (affinity 0–8). Modules were compiled before measurement; process startup and compilation are excluded, while loading the compiled test modules and their checks is included. A full garbage collection precedes each timed region. CPU frequency and host load were not controlled, so results vary with the machine and the version of Racket.
amb is slower and allocates substantially more in both editions. Choices, pauses and local searches use continuation and generator machinery in place of stream pairs and suspensions; in the first edition, each nonfinal conjunction introduces a local search. The larger allocation is consistent with that mechanism, but this whole-module measurement does not isolate how much CPU time is spent capturing or restoring continuations.
The measurement record lists the raw samples and links to the benchmark instructions.