benchpress: A Self-Building Benchmark Harness Generator

Recently, I was bored and decided to test the performance of a 4x4 matrix multiply. I wanted to compare how GCC and Clang optimize the same code with different flags. So I manually wrote a benchmark harness using a neat trick: a C file that’s also a valid shell script. The idea is simple. You embed shell commands in C comments at the top of the file. When you run sh benchmark.c, the shell sees the commands and executes them to compile and run the benchmark. When the C compiler processes it, the commands are just comments. ...

November 16, 2025 · 4 min