RMath

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.

OperationBaselineSpeedupDescription
sum_rangePython sum(range)4,568.30xO(1) Rust math vs O(n) loop.
diffPython List Comp261.32xParallel difference kernel.
sqrtPython List Comp222.26xSIMD-accelerated square root.
variancestatistics.variance98.60xSingle-pass Welford algorithm.
vector addPython List Comp86.68xParallel element-wise ops.
randnrandom.gauss84.00xParallel 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.

OperationBaselineSpeedupDescription
from_numpyNumPy Array113.35xZero-copy buffer handoff.
transposeNumPy .T108.88xLazy dimension remapping.
inverseNumPy inv12.55xParallel LU decomposition.
geluNumPy Logic11.55xSIMD-accelerated activation.
randnNumPy randn7.44xParallel 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.

OperationBaselineSpeedupDescription
cdf/pdfSciPy norm500x+Bypassing Python wrapper overhead.
medianstatistics50.96xOptimized introselect algorithm.
describe()SciPy describe13.35xOne-pass summary statistics.
correlationSciPy pearsonr7.61xParallel Pearson correlation.
t-testSciPy ttest1.99xHigh-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.

OperationBaselineSpeedupDescription
trapezoidalNumPy trapz7.79xParallel integration kernel.
Exact GradAnalyticNativeZero-error Dual Number AD.

Spatial Geometry & Signal

Native Rust kernels for spatial analysis and spectral transformations.

OperationBaselineSpeedupDescription
3D CrossNumPy cross49.99xSIMD-accelerated cross product.
Convex HullPython Algo6.11xMonotone Chain algorithm in Rust.
MinkowskiNumPy norm4.78xParallel spatial distance metric.
FFT (4096)NumPy fft3.62xHigh-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.

OperationBaselineSpeedupDescription
var of rangePython _py_var75.35xFused Welford variance pipeline.
filter + sumPython GenExp72.38xSIMD-accelerated branchless filtering.
sum of rangePython sum()54.06xParallel reduction across CPU cores.
sin+sqrt+sumPython Loop44.72xOperation 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.

OperationBaselineSpeedupDescription
reshapePyTorch .view7.04xO(1) layout transformation.
add (grad)PyTorch +7.00xFused addition with gradient tape.
backwardPyTorch .backward5.99xLean tape traversal in native Rust.
sigmoidPyTorch sigmoid5.53xVectorized activation with Autograd.
transposePyTorch .T1.90xLazy 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 Steprmath Timermath MemNumPy TimeNumPy MemSpeedup
Data Generation0.30s153 MB1.31s137 MB4.3× faster
Data Cleaning0.15s0.5 MB0.17s4.8 MB1.1× faster
Feature Engineering0.07s76 MB0.12s76 MB1.8× faster
Descriptive Stats0.26s0.07 MB0.25s0.03 MBComparable
Correlation Analysis0.038s0.04 MB0.43s0.13 MB11.2× faster
Segmentation0.47s120 MB0.93s38 MB2.0× faster
Linear Signal0.16s0.03 MB0.13s0.00 MBNumPy 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/.