code wiki / _hdl_build / nx_eqsat_race_bench.nx
nx_eqsat_race_bench.nx
buildroot/runtime/_hdl_build/nx_eqsat_race_bench.nx
about
nx_eqsat_race_bench.nx -- RACE TIMING HARNESS vs egg 0.11.0 on the SAME task.
THE RACE: egg's /tmp/race_egg/examples/nx_race.rs timed E2
"(* x 8)" : parse-string -> RecExpr -> Runner -> saturate ->
Extractor::find_best -> to_string == (<< x 3)
100000 iterations = 783465 us total = 7.835 us/op (LatCost model).
OUR analogue, ONE timed iteration (the same end-to-end pipeline, no proxy):
nx_eqsat_init (fresh e-graph -- egg's RecExpr alloc)
add_var x, add_const 8,
add_binary(MUL, x, 8) (BUILD the (* x 8) input -- egg's parse)
nx_eqsat_saturate(g, 16) (egg's Runner::run to saturation)
nx_eqsat_recompute_best(g) (egg's Extractor bottom-up cost pass)
nx_eqsat_extract_best_node(mul) (egg's find_best for the mul e-class)
read the root op of that node (egg's to_string root-symbol read)
CONFIRM the extracted op == NX_EQ_OP_SHL (11) and shift const == 3.
Everything that egg counted (parse->saturate->extract->stringify-root) is
inside OUR timed loop too, so the us/op is comparable 1:1. We do NOT include
the membership PROOF/provenance machinery (egg has none) -- only the same
optimize-and-read-the-answer work egg performed.
FAIL LOUD: if the extracted representative is not (shl x 3) the harness
sys_exit(nonzero) BEFORE printing timing -- a fast wrong answer is not a win.
Output (one line): RESULT_OP=11 SHIFT=3 ITERS=100000 TOTAL_US=<t> US_PER_OP=<u>
dependencies 1 imports · 0 importers
imports: nx_eqsat.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 29 | const K_MAGIC_100000: i64 = 100000 |
functions
| 32 | func _emit_num(v: i64) -> i64 called by 1: main |
| 47 | func _emit_str(s: *u8, len: i64) -> i64 called by 1: main |
| 52 | func _nl() -> i64 called by 1: main |
| 68 | func _one_iter(eg: *NxEGraph, |
| 96 | func main() -> i64 |