r/Compilers • u/Randozart • Jun 03 '26
Need good benchmarks for custom language vs. C.
I am currently designing a programming language called Brief. It's declarative for the most part, and because it describes state transitions more than it does commands, I theorized I could optimize the compiler to outperform clang over C. So, I keep running benchmarks against C using random programs I've written in either language, trying my best to write the best, most clean and optimized C code I can.
However, I know there is far more accomplished programmers out there who can likely write better programs than I can. I need some solid benchmark programs that represent the pinnacle of what C is capable of, so I can see where Brief still has has clear latency, and figure out by looking at the binaries what compiler optimization I might still need to do. Note that, in the screenshot below, you will already find some broken benchmarks. 0.0006s vs. 0.0836s was a fluke due to a quirk in what the Brief compiler considered dead code.

For reference, here is a Kalman filter I test against, just to see how I try to optimize my code. But I need some solid proven benchmarks if possible to get a good, genuinely challenging benchmark to compare and optimize against:
#include <stdlib.h>
int main(void) {
const char* env = getenv("BOUND");
long total = env ? atol(env) : 50000000L;
// State vector (3 floats)
float x0 = 0.0f, x1 = 0.0f, x2 = 0.0f;
// Covariance matrix P (9 floats, row-major: P[row*3 + col])
float p00 = 0.1f, p01 = 0.0f, p02 = 0.0f;
float p10 = 0.0f, p11 = 0.1f, p12 = 0.0f;
float p20 = 0.0f, p21 = 0.0f, p22 = 0.1f;
// A matrix (constant, row-major)
const float a00 = 1.0f, a01 = 0.01f, a02 = 0.00005f;
const float a10 = 0.0f, a11 = 1.0f, a12 = 0.01f;
const float a20 = 0.0f, a21 = 0.0f, a22 = 1.0f;
// Q matrix (constant, row-major)
const float q00 = 0.001f, q01 = 0.0f, q02 = 0.0f;
const float q10 = 0.0f, q11 = 0.001f, q12 = 0.0f;
const float q20 = 0.0f, q21 = 0.0f, q22 = 0.001f;
long count = 0;
for (; count < total; count++) {
// State propagation: x_new = A * x
float nx0 = a00 * x0 + a01 * x1 + a02 * x2;
float nx1 = a10 * x0 + a11 * x1 + a12 * x2;
float nx2 = a20 * x0 + a21 * x1 + a22 * x2;
// Covariance propagation: P_new = A * P * A^T + Q
// Step 1: AP = A * P
float ap00 = a00 * p00 + a01 * p10 + a02 * p20;
float ap01 = a00 * p01 + a01 * p11 + a02 * p21;
float ap02 = a00 * p02 + a01 * p12 + a02 * p22;
float ap10 = a10 * p00 + a11 * p10 + a12 * p20;
float ap11 = a10 * p01 + a11 * p11 + a12 * p21;
float ap12 = a10 * p02 + a11 * p12 + a12 * p22;
float ap20 = a20 * p00 + a21 * p10 + a22 * p20;
float ap21 = a20 * p01 + a21 * p11 + a22 * p21;
float ap22 = a20 * p02 + a21 * p12 + a22 * p22;
// Step 2: P_new = AP * A^T + Q
p00 = ap00 * a00 + ap01 * a10 + ap02 * a20 + q00;
p01 = ap00 * a01 + ap01 * a11 + ap02 * a21 + q01;
p02 = ap00 * a02 + ap01 * a12 + ap02 * a22 + q02;
p10 = ap10 * a00 + ap11 * a10 + ap12 * a20 + q10;
p11 = ap10 * a01 + ap11 * a11 + ap12 * a21 + q11;
p12 = ap10 * a02 + ap11 * a12 + ap12 * a22 + q12;
p20 = ap20 * a00 + ap21 * a10 + ap22 * a20 + q20;
p21 = ap20 * a01 + ap21 * a11 + ap22 * a21 + q21;
p22 = ap20 * a02 + ap21 * a12 + ap22 * a22 + q22;
// Update state vector
x0 = nx0;
x1 = nx1;
x2 = nx2;
}
return (int)(count + x0 + x1 + x2 +
p00 + p01 + p02 + p10 + p11 + p12 + p20 + p21 + p22);
}
12
u/suhcoR Jun 03 '26
The Are-we-fast-yet benchmark suite is very useful, with a decent rule set and scientific grounding. I've been using it for many years and ported it to different languages including my own: https://github.com/rochus-keller/are-we-fast-yet/
The Computer Language Benchmark Game in contrast mostly focuses on microbenchmarks and has no strict rule set for the implementations. There are even different implementations per benchmark, which makes comparison more difficult.
The purpose of a benchmark suite is not to achieve optimal or maximum absolute performance, but to provide an established, deterministic means of comparing implementations and making design decisions based on reliable measurements, acknowledging that every measurement carries an inherent error margin.
7
u/zsaleeba Jun 03 '26
Check out the Computer Language Benchmark Game. They have nicely written code in multiple languages for a decent variety of benchmarks.
https://madnight.github.io/benchmarksgame/
2
u/glvz Jun 03 '26
Write a dgemm!
2
u/matthieum Jun 03 '26
How are you compiling Brief to assembly?
If you're using LLVM, then keep using Clang to compile C.
If you're generating the assembly yourself, however, you may want to benchmark against both of Clang and GCC, as they generally produce slightly different programs.
2
u/Karyo_Ten Jun 03 '26
Use some of the popular programming language benchmarks out there, there are plenty. And plebty of people explaining thousands how each bench is flawed.
2
u/mamcx Jun 03 '26
ASIDE:
To benchmark is to answer the question of "What are you trying to optimize?".
You should have this very clear, or you will waste time benchmarking things that are not relevant.
There are a few obvious things like how fast you can parse, load modules, etc, pure guardrails against regression, but there are more important things: You are targeting games, web apps, low level FFI? think look for things that matter there.
2
u/Tasty_Replacement_29 Jun 04 '26
I have implementations of 6 algorithms. 5 are from "The Computer Language Benchmarks Game". For the following languages: C, Go, Java, Nim, PyPy, Rust, Swift, Vlang, Zig, and my language (Bau). I try to ensure the exact same algorithm is used for each language, except for the one that needs a bigint library (calculating digits of Pi).
I recently added a test to measure stop-the-world pauses based on https://lemire.me/blog/2026/02/15/how-bad-can-python-stop-the-world-pauses-get/ , in Go, Java, PyPy, Python, Rust, Swift, and my language.
2
u/[deleted] Jun 03 '26 edited Jun 03 '26
[removed] — view removed comment