Repository navigation
refactor(bench): give the three benchmark tools one shared definition (#101) - #108
Merged
Merged
Conversation
CORELIB_PLAN §10 requires `bench`, `perf` and `run_callgrind.sh` to follow one specification so their numbers stay comparable across languages. The pieces that specification constrains were copied instead of shared, so the three tools could drift apart without anything noticing: * `OStreamRaw` / `IStreamRaw` — the harnesses' only view of the corelib's public surface — were declared verbatim in both bench.cpp and perf.cpp. * `cpu_now()`, `kBlockSeconds` and the doubling block-calibration loop, i.e. BENCH_SPEC's timing rules, were duplicated as well. * The workload names lived in three places: the `strcmp` chain in bench.cpp, the `WORKLOADS` array plus a second copy in `label()` in run_callgrind.sh, and the `foreach` in bench/CMakeLists.txt. The adapters and the whole measured loop now live once in bench/bench_common.hpp, included by both harnesses. The workloads live once in a table in bench.cpp that the timed run, the Callgrind single-shot mode and the new `bench --list` all walk; run_callgrind.sh takes both the names and the row labels from that output, and the run_bench_callgrind CMake target delegates to the script rather than repeating the list. Measured Ir/op is unchanged on all four workloads. run_callgrind.sh also stops swallowing a failed measurement: a Callgrind run that exits non-zero, or a row with no instruction count or message size, now aborts with the captured diagnostic instead of printing a table cell that reads `-`. Regression test: bench/test_bench_tools.sh, wired into CTest as `test_bench_tools`. It checks that every published workload runs and reports its size, that an unknown name is rejected, that neither run_callgrind.sh nor bench/CMakeLists.txt keeps a copy of the workload list, and that bench.cpp and perf.cpp take the adapters and the timing harness from the shared header. It also drives run_callgrind.sh end to end against a stub `valgrind`, so it needs no Valgrind and still proves a failing run aborts the table. Closes #101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #101.
CORELIB_PLAN §10 wants
bench,perfandrun_callgrind.shto follow one specification (BENCH_SPEC) so their numbers stay comparable across languages. The pieces that specification constrains were copied rather than shared.What moved
bench/bench_common.hpp(new) — the stream adaptersOStreamRaw/IStreamRaw(the harnesses' only view of the corelib's public surface) and the timing harness:cpu_now(), the cycle counter,kBlockSecondswith its justifying comment,calibrateBlock()and the ~1 s measured loop.bench.cppandperf.cppboth include it;perf'sPerfResultis now the sharedMeasureResult, so the two tools cannot time differently.Workloadtable inbench.cpp(name, row label, setup, measured op, byte count). The timed table, the single-shot Callgrind mode and the newbench --listall walk it, so thestrcmpchain can no longer disagree with what is listed.run_callgrind.shpopulatesWORKLOADSand its row labels frombench --list(name<TAB>label), and its secondlabel()copy is gone.bench/CMakeLists.txt'srun_bench_callgrinddelegates to the script instead of repeating the names in aforeach.run_cg()now checks the Callgrind exit status and prints the captured stderr, and a row with nosummary:line or noBYTES=aborts the run. Previously a broken row died silently (stderr went to a discarded log) or would have printed a-, which looks exactly like a fresh table.Numbers
Unchanged, measured against
mainon the same host:Regression test
bench/test_bench_tools.sh, wired into CTest astest_bench_tools(skips when the build produced nobenchbinary). It fails onmain— the first check,bench --list, does not exist there. It asserts:BYTES=, and an unknown name is rejected with a diagnostic;run_callgrind.shnorbench/CMakeLists.txtcontains any published workload name or row label (no second copy of the list);bench.cppandperf.cppincludebench_common.hppand declare noOStreamRaw/IStreamRaw/cpu_now/kBlockSecondsof their own;run_callgrind.shend to end against a stubvalgrind— one row per published workload on success, and a non-zero exit carrying the failing run's diagnostic when the measurement fails. No Valgrind needed, runs in ~0.3 s.Note on the issue text
The issue expected a rejected workload to print a row of dashes and exit 0. It does not:
set -euo pipefailalready turns the failingrun_cginto an abort — but a completely silent one, mid-table, with the diagnostic in a discarded temp file. That half is fixed as described above rather than as reported.README's Benchmarks and Build & test sections updated (new suite,
bench --list, the single-source rule, and the CMake target's changed behaviour).