Skip to content

Benchmarks ​

Lazy normalization preserves sparse storage. Eager normalization constructs a dense normalized matrix. Compare a complete regression fit, including peak memory, and then individual operations with setup excluded.

8,192 × 512 rows × columns · f64 · mean centering + SD scaling
The normalized dense matrix alone occupies 32 MiB.

A complete fit

Fit ridge regression with gradient descent across seven nonzero densities, from 0.1% to 100%. Both paths use the same data, algorithm, and accuracy target, starting with the raw sparse input.

Total wall-clock time

Complete ridge fit time versus nonzero density for 8,192 × 512 matrices, comparing lazy sparse and eager dense normalization.
Includes fitting normalization parameters, materialization for eager, step-size estimation, and solving to convergence. Shading shows 95% confidence intervals. Lower is faster. Download SVG.

Peak memory during the fit

Peak live Rust allocation bytes across normalization and a complete ridge fit versus density for 8,192 × 512 matrices.
The largest live allocation total from normalization through convergence, including the source matrix, response, normalized storage, and solver workspace. Both paths retain the source. Lower uses less memory. Download SVG.

Memory counts requested Rust bytes, excluding allocator overhead and native-library allocations. It does not measure total process RAM.

Fit measurements and convergence

Both paths satisfy the same gradient tolerance and produce matching coefficients and objectives. Iterations count coefficient updates; the CSV also records the objective and final gradient norm.

Nonzeros (%)StrategyTotal (ms)Peak (MiB)Iterations
0.101Lazy sparse2.8030.21737
0.101Eager dense3,586.53532.21337
0.302Lazy sparse3.2560.34627
0.302Eager dense2,592.19232.34227
1.001Lazy sparse6.9780.79326
1.001Eager dense2,624.95132.78926
2.997Lazy sparse14.7462.0726
2.997Eager dense2,470.88934.06726
9.981Lazy sparse43.8946.5426
9.981Eager dense2,436.3938.53726
29.972Lazy sparse136.45419.33426
29.972Eager dense2,543.67251.3326
100Lazy sparse586.17864.15227
100Eager dense3,299.30596.14827

Individual operations

These timings measure one product with normalization already fitted and eager storage already materialized. Outputs are reused; any scratch allocation inside the operation is included.

Forward product: X̃v

Forward product time excluding setup versus density for 8,192 × 512 matrices, comparing lazy sparse and eager dense operators.
Multiply by a coefficient vector. Shading shows 95% confidence intervals. Lower is faster. Download SVG.

Transpose product: X̃ᵀu

Transpose product time excluding setup versus density for 8,192 × 512 matrices, comparing lazy sparse and eager dense operators.
Multiply by a vector of observations. Shading shows 95% confidence intervals. Lower is faster. Download SVG.
Operation measurements and memory breakdown

The memory column includes normalization, eager construction, and ten forward/transpose pairs, with the sparse source retained. This is a separate workload from the complete fit above. The CSV includes normalized storage, workspace, setup timings, and raw sparse timings.

Nonzeros (%)StrategyForward (µs)Transpose (µs)Peak (MiB)
0.101Lazy sparse21.42120.6550.213
0.101Eager dense2,014.33956,119.12632.209
0.302Lazy sparse28.97128.9970.342
0.302Eager dense2,914.56769,790.23332.338
1.001Lazy sparse93.63671.1630.789
1.001Eager dense1,793.02663,598.90932.785
2.997Lazy sparse234.338213.0362.067
2.997Eager dense2,881.03846,105.33634.063
9.981Lazy sparse341.296266.8516.537
9.981Eager dense1,435.45844,911.21938.533
29.972Lazy sparse1,044.502919.94619.33
29.972Eager dense1,459.73245,563.34651.326
100Lazy sparse3,037.5983,109.3964.148
100Eager dense1,398.14745,997.75296.145

October 27, 2026 · Intel(R) Core(TM) Ultra 7 155U · 1 thread · 30 timing samples per case. Both axes use logarithmic scales. Points show measured nonzero densities; lines connect the samples.

Fit measurements (CSV) · Operation measurements (CSV) · Run metadata

Methodology ​

These are synthetic, single-threaded comparisons of sparse lazy normalization and dense eager normalization. Each backend uses its own dense destination. They illustrate the trade-off for this workload; the faster choice depends on the data, operations, and hardware.

Complete regression fit ​

Both paths solve the same ridge problem in normalized coordinates:

min⁡β  12n∥X~β−y∥22+0.12∥β∥22.\min_\beta\; \frac{1}{2n}\lVert \widetilde X\beta-y\rVert_2^2 + \frac{0.1}{2}\lVert\beta\rVert_2^2.

The shared gradient descent example uses reusable output buffers and starts from zero coefficients. Each fit includes 30 power iterations to estimate an initial step size, followed by gradient descent with backtracking. Both representations stop when the gradient's L2 norm is at most 10−7max⁡(1,∥g0∥2)10^{-7}\max(1,\lVert g_0\rVert_2), where g0g_0 is the initial gradient. The harness rejects unconverged fits and checks that coefficients and objectives agree before timing. The downloadable results include iteration counts, objectives, and final gradient norms.

Timing starts with the raw matrix and response already allocated. It includes fitting centers and scales, dense materialization for the eager path, all solver setup, solving to convergence, and dropping the fitted result. Each timed fit starts afresh. Fixture generation and backend conversion are excluded.

Peak memory ​

A separate executable measures the largest increase in live requested Rust bytes across normalization, materialization, and the complete solve. It adds the original sparse input and response, which both paths retain throughout the fit. This includes the eager dense matrix and solver workspace while they are live. It measures the complete workflow directly; it does not add phase peaks.

The figures exclude allocator overhead, native-library allocations, and unrelated process state. They measure allocation bytes rather than process RAM. Reallocation is recorded at its resulting size. An application that releases its source after eager construction may retain less memory during solving, though construction still requires the source and destination to coexist.

Fixtures and individual operations ​

The size selector offers 2,048 × 128, 8,192 × 512, and 16,384 × 1,024 matrices and updates all four charts and their tables. Dimensions are rows × columns. Matrices use canonical CSC storage, f64 values, and usize indices. Fixtures use ChaCha8Rng with seed 205 and target nonzero fractions 0.001, 0.003, 0.01, 0.03, 0.1, 0.3, and 1. Each cell is selected independently. Stored values are positive, with varying column scales, so centering generally turns structural zeros into nonzero logical values. The response is the deterministic sequence yi=sin⁡(0.13i)+0.5cos⁡(0.037i)y_i=\sin(0.13i)+0.5\cos(0.037i), starting at i=0i=0. Mean centering and SD scaling are fitted separately for each complete fit; exact zero scales are replaced with one.

Individual products reuse the matrix, fitted parameters, input vectors, and output buffers. They include any scratch allocation inside the public *_into methods. Forward and transpose inputs are deterministic, nonconstant vectors with nonzero sums. The harness checks products against the eagerly normalized matrix before timing.

Timings use Criterion means and 95% bootstrap confidence intervals. The 8,192 × 512 collection uses 30 samples, 0.3 seconds of warmup, at least one second of measurement, and 10,000 bootstrap resamples. The other sizes use ten samples, 0.05 seconds of warmup, at least 0.1 seconds of measurement, and 1,000 resamples. Long fits extend measurement to collect the requested samples. Compilation and allocation profiling finish before timing begins. Intervals describe variation on the collection machine; they do not describe variability across hardware or sparse patterns. The run metadata records the CPU, compiler, collection date, thread settings, and solver settings.

Reproduce ​

sh
# Collect complete fits, operation timings, and allocation profiles.
bash scripts/bench-least-squares.sh

# Use shorter timing settings for a quick comparison.
LAZYMATRIX_BENCH_QUICK=1 bash scripts/bench-least-squares.sh

# Publish a checked collection and regenerate the website plots.
mkdir -p benches/least_squares
cp target/least-squares/{results.csv,products.csv,metadata.json} benches/least_squares/
task website:check

# Check small fixtures and convergence without collecting timing samples.
LAZYMATRIX_BENCH_SMOKE=1 cargo bench --locked --bench least_squares \
  --features ndarray,sprs,faer -- --test

The website builds its charts from checked-in measurements. It never runs benchmarks. The measurement notes describe the collector and its outputs.

Additional measurements

The operation CSV also contains SD scaling without centering, unnormalized sparse products, setup timings, and memory breakdowns. Scaling alone preserves structural zeros; its dense eager path compares with the crate's dense materialization API rather than an optimized sparse scaling strategy.

The earlier full operation sweep covers tall, square, and wide matrices at 2, 32, and 128 MiB of dense storage. It was collected on a different machine; its metadata and measurement notes remain available. Earlier consumer fitting profiles are also retained separately.

Released under the MIT and Apache 2.0 licenses.