Performance comparison testing system for Zigen vs Eigen 5.0.0.
cd bench
# Default: dim 64, f64
./run_benchmark.sh
# Custom dimension
./run_benchmark.sh --dim 128
# Full sweep: dims 64,256,1024 × f32,f64
./run_benchmark.sh --all
# Single precision
./run_benchmark.sh --precision f32
# Fixed random seed
./run_benchmark.sh --seed 42Results are generated in bench/tmp/output_<platform>/:
tmp/output_mac26_aarch_m3pro/
├── results.md # Markdown report with tables
├── dim64_f64/
│ ├── zigen_bench.txt # Raw Zigen timing output
│ ├── eigen_bench.txt # Raw Eigen timing output
│ ├── zigen_results.txt # Zigen numeric results
│ └── eigen_results.txt # Eigen numeric results
└── test_data_dim64/ # Generated test matrices
28 tests covering all major operations:
| No. | Category | Tests |
|---|---|---|
| 1-6 | Matrix Ops | Add, Sub, Mul, Transpose, Trace, Determinant |
| 7-10 | Vector Ops | Dot, Cross, Normalize, Norm |
| 11-13 | Decompositions | LU, QR, Cholesky |
| 14-17 | Quaternions | Mul, Normalize, toRotationMatrix, SLERP |
| 18-19 | Extended | SVD, EigenSolver |
| 20-21 | Solve | Inverse, Linear Solve Ax=b |
| 22-24, 27-28 | Dynamic | Mul, LU, QR, Cholesky, Transpose |
| 25-26 | Sparse | SpMV, SparseLU Solve |
All benchmark loops use zero-allocation APIs to ensure fair comparison with Eigen:
- Workspace reuse:
init()+computeFrom()for decompositions - In-place operations:
addInto(),mulInto(),transposeInto() - Buffer writes:
solveInto(),mulVecInto(),inverseDynamicInto()
This eliminates allocator overhead from timing measurements, matching Eigen's stack-based approach.
| File | Description |
|---|---|
run_benchmark.sh |
Main benchmark script (compile, run, verify, report) |
benchmark_zigen.zig |
Zigen benchmark entry point |
benchmark_eigen.cpp |
Eigen benchmark entry point |
generate_test_data.py |
Test data generator (NumPy) |
generate_report.py |
Markdown report generator |
zigen/*.zig |
Zigen benchmark modules (basic_matrix, dynamic, extended, sparse, etc.) |
eigen/*.hpp |
Eigen benchmark modules |
- Zig 0.16.0+
- C++17 compiler (clang++/g++)
- Eigen 5.0.0 (at
../eigen-5.0.0or setEIGEN_PATH) - Python 3 (with NumPy, for data generation)
Before reporting performance, the script verifies that Zigen and Eigen produce matching results:
| Precision | Absolute Tolerance |
|---|---|
| f32 | 0.0001 |
| f64 | 0.000001 |
Note: For very large values (e.g., determinants at high dimensions), the absolute difference may exceed the tolerance even though the relative error is at machine epsilon. These are flagged as warnings but do not prevent report generation.