Performance Audit
RMath benchmarks are executed head-to-head against industry standards.
Below are verified results from our v0.1.5+ performance suite, including
micro-benchmarks per module and a real-world 5M-row data pipeline comparison.
Detailed Vector Speedups (N=100,000)
Across descriptive statistics and linear algebra, RMath provides significant
latency reduction on CPU.
| Operation | Baseline | Speedup | Description |
sum_range | Python sum(range) | 4,568.30x | O(1) Rust math vs O(n) loop. |
diff | Python List Comp | 261.32x | Parallel difference kernel. |
sqrt | Python List Comp | 222.26x | SIMD-accelerated square root. |
variance | statistics.variance | 98.60x | Single-pass Welford algorithm. |
vector add | Python List Comp | 86.68x | Parallel element-wise ops. |
randn | random.gauss | 84.00x | Parallel PRNG filling. |
Average Speedup: Our automated test suite (167 tests) reports an
average performance increase of 46.02x over equivalent NumPy/Python paths.
Array Operations (500x200)
RMath excels at memory layout transformations and specialized neural network kernels.
| Operation | Baseline | Speedup | Description |
from_numpy | NumPy Array | 113.35x | Zero-copy buffer handoff. |
transpose | NumPy .T | 108.88x | Lazy dimension remapping. |
inverse | NumPy inv | 12.55x | Parallel LU decomposition. |
gelu | NumPy Logic | 11.55x | SIMD-accelerated activation. |
randn | NumPy randn | 7.44x | Parallel Gaussian filling. |
Matrix Scaling: For multidimensional arrays, RMath provides an
average 4.79x speedup across 161 automated tests.
Statistical Inference (N=100,000)
RMath implements distribution kernels in native Rust, significantly reducing
function call overhead and improving numerical stability.
| Operation | Baseline | Speedup | Description |
cdf/pdf | SciPy norm | 500x+ | Bypassing Python wrapper overhead. |
median | statistics | 50.96x | Optimized introselect algorithm. |
describe() | SciPy describe | 13.35x | One-pass summary statistics. |
correlation | SciPy pearsonr | 7.61x | Parallel Pearson correlation. |
t-test | SciPy ttest | 1.99x | High-precision Welch kernel. |
Statistical Mastery: Across our inference suite, RMath delivers an
average 184.35x performance gain over standard SciPy paths.
Calculus & Integration
RMath provides high-precision numerical integration and exact Automatic
Differentiation (AD) using Dual Numbers.
| Operation | Baseline | Speedup | Description |
trapezoidal | NumPy trapz | 7.79x | Parallel integration kernel. |
Exact Grad | Analytic | Native | Zero-error Dual Number AD. |
Spatial Geometry & Signal
Native Rust kernels for spatial analysis and spectral transformations.
| Operation | Baseline | Speedup | Description |
3D Cross | NumPy cross | 49.99x | SIMD-accelerated cross product. |
Convex Hull | Python Algo | 6.11x | Monotone Chain algorithm in Rust. |
Minkowski | NumPy norm | 4.78x | Parallel spatial distance metric. |
FFT (4096) | NumPy fft | 3.62x | High-performance spectral transform. |
Scalar Pipelines (N=100,000)
RMath uses a LazyPipeline architecture for scalar operations. While
individual scalar arithmetic pays an FFI tax, bulk pipeline processing
bypasses the Python interpreter entirely.
| Operation | Baseline | Speedup | Description |
var of range | Python _py_var | 75.35x | Fused Welford variance pipeline. |
filter + sum | Python GenExp | 72.38x | SIMD-accelerated branchless filtering. |
sum of range | Python sum() | 54.06x | Parallel reduction across CPU cores. |
sin+sqrt+sum | Python Loop | 44.72x | Operation fusion (zero allocation). |
Pipeline Efficiency: By batching operations, RMath Pipelines achieve
an average 33x–75x speedup over pure Python loops.
Tensor Training Steps (200x200)
RMath Autograd is optimized for smaller to medium-sized tensors where framework
overhead in PyTorch/TensorFlow usually dominates.
| Operation | Baseline | Speedup | Description |
reshape | PyTorch .view | 7.04x | O(1) layout transformation. |
add (grad) | PyTorch + | 7.00x | Fused addition with gradient tape. |
backward | PyTorch .backward | 5.99x | Lean tape traversal in native Rust. |
sigmoid | PyTorch sigmoid | 5.53x | Vectorized activation with Autograd. |
transpose | PyTorch .T | 1.90x | Lazy dimension remapping. |
Autograd Performance: In CPU-bound training scenarios, RMath
Autograd delivers a 4.16x average speedup over PyTorch.
Real-World Data Pipeline — rmath vs NumPy
End-to-end benchmark on a 5 million row financial dataset.
Measured on Windows (CPython 3.13, AMD64). Both libraries perform identical
pipeline stages: generation, cleaning, feature engineering, statistics,
correlation, segmentation, and linear signal extraction.
| Pipeline Step | rmath Time | rmath Mem | NumPy Time | NumPy Mem | Speedup |
| Data Generation | 0.30s | 153 MB | 1.31s | 137 MB | 4.3× faster |
| Data Cleaning | 0.15s | 0.5 MB | 0.17s | 4.8 MB | 1.1× faster |
| Feature Engineering | 0.07s | 76 MB | 0.12s | 76 MB | 1.8× faster |
| Descriptive Stats | 0.26s | 0.07 MB | 0.25s | 0.03 MB | Comparable |
| Correlation Analysis | 0.038s | 0.04 MB | 0.43s | 0.13 MB | 11.2× faster |
| Segmentation | 0.47s | 120 MB | 0.93s | 38 MB | 2.0× faster |
| Linear Signal | 0.16s | 0.03 MB | 0.13s | 0.00 MB | NumPy slight edge |
Pipeline Winner: rmath wins 5 of 7 stages on speed.
Data cleaning uses 9× less memory than NumPy (0.5 MB vs 4.8 MB)
thanks to zero-allocation filter_where.
Full benchmark scripts available in benchmarks/pipeline/.