Performance
Gate B is equivalent-n loops: Buraaq --release versus C++ -O2, clang 22. The same n is in both sources. Unfavorable numbers stay published.
Results
| Bench | n | C++ -O2 | Buraaq | Ratio |
|---|---|---|---|---|
| nested_loop | 1e4² | 0.010s | 0.002s | 0.16× |
| integer_sum | 1e8 | 0.015s | <0.001s | 0.00× |
| float_saxpy | 1e7 | 0.004s | 0.004s | 0.97× |
| numerical_loop | 1e8 | 0.083s | 0.084s | 1.01× |
| fib_iter | 1e8 | 0.020s | 0.021s | 1.02× |
Four benches beat or match C++. integer_sum is an Orbit fold of wrapping sum = sum * 3 + i (same n=1e8; n=10 checksum 44281). Worst published: fib_iter 1.02×. n was not reduced.
What we measure
- Timed region is only the loop. Setup and print sit outside the clock.
nis kept alive (volatilein C++,buraaq_keepalive_i32in Buraaq) so the optimizer cannot delete the work.- Buraaq signed
add/subemit LLVMnsw, the same flag clang uses for C++ signed math. for i in 1..=nparses whennis an identifier (the end of a range is not a struct literal).
How to write a hot loop
Write the obvious while or for. Measure --release before you clever it. --release-fast is -O3 plus thin LTO when you care about the last percent.
fn main() {
n = 100000000
mut sum = 0
mut i = 1
while i <= n {
sum = sum * 3 + i
i = i + 1
}
println(sum)
}
Do not drop bounds checks or reach for unsafe to “win” a bench. Gate B was taken in safe Buraaq.
Next: electronics if the loop sits on a board.
