kstats Benchmarks

March 22, 2026 · View on GitHub

JMH-based performance comparison between kstats and Apache Commons Math 3.

All benchmarks use kotlinx-benchmark with JMH under the hood. Each benchmark method has a kstats* and commons* variant so the two libraries are measured under identical conditions.

Environment

ParameterValue
JVMOpenJDK 21.0.10 (Homebrew)
ArchitectureApple Silicon (aarch64)
JMH1.37 via kotlinx-benchmark
Warmup5 iterations x 3 s
Measurement5 iterations x 3 s
ModeAverage time (avgt)
Unitmicroseconds per operation (μs/op)

Running Benchmarks

# Full benchmark run (~40 min)
./gradlew :benchmark:benchmark

# Quick smoke test (~5 min)
./gradlew :benchmark:smokeBenchmark

Reports are written to benchmark/build/reports/benchmarks/main/<timestamp>/main.json in JMH-compatible JSON format.

Benchmark Profiles

ProfileWarmupMeasurementIteration Time
main5 iterations5 iterations3 s
smoke2 iterations3 iterations1 s

Available Benchmarks

Descriptive Statistics

ClassMethodsParameters
DescriptiveStatsBenchmarkmean, variance, stdDev, geometricMean, median, skewness, kurtosis, describesize: 100, 1K, 10K, 100K
QuantileBenchmarkpercentile50, percentile95, iqrsize: 1K, 10K, 100K

Correlation & Regression

ClassMethodsParameters
CorrelationBenchmarkpearson, spearman, kendallTau, linearRegressionsize: 100, 1K, 10K
CovarianceBenchmarkcovariancesize: 100, 1K, 10K

Hypothesis Tests

ClassMethodsParameters
HypothesisTestBenchmarkoneSampleTTest, twoSampleTTest, oneWayAnova, chiSquared, mannWhitney, kolmogorovSmirnovsize: 100, 1K, 10K
PairedTTestBenchmarkpairedTTestsize: 100, 1K, 10K
ChiSquaredIndependenceBenchmarkchiSquaredIndependencetableSize: 3, 10, 50

Probability Distributions

ClassDistributionsOperations
ContinuousDistributionBenchmarkNormal, Beta, Gamma, Chi-Squared, Student's t, Exponentialpdf, cdf, quantile
DiscreteDistributionBenchmarkBinomial, Poissonpmf, cdf
FDistributionBenchmarkFpdf, cdf, quantile
CauchyBenchmarkCauchypdf, cdf, quantile
UniformContinuousBenchmarkUniformpdf, cdf, quantile
WeibullBenchmarkWeibullpdf, cdf, quantile
LogNormalBenchmarkLogNormalpdf, cdf, quantile
GeometricBenchmarkGeometricpmf, cdf, quantile
HypergeometricBenchmarkHypergeometricpmf, cdf, quantile
ZipfDistributionBenchmarkZipfpmf, cdf, quantile

Results

Overall Comparison

Overview

Where kstats wins (>1.5x faster)

OperationSpeedup
Zipf (pmf, cdf, quantile)6,700–47,000x
LogNormal quantile443x
Chi-Squared Independence (3x3)58x
Chi-Squared GOF39x
LogNormal pdf/cdf8–10x
ANOVA5.1x
Kurtosis4.2x
Geometric quantile3.4x
Weibull quantile3.0x
F distribution (pdf, cdf, quantile)1.7–2.5x
Normal CDF2.1x
Pearson correlation1.8x
Cauchy quantile1.7x
Geometric pmf1.6x
Linear regression1.6x
Covariance1.5x

Where Commons Math wins (>1.5x faster)

OperationSpeedup
Normal quantile14.0x
Describe (all stats)6.6x
Binomial pmf4.2x
Paired t-test4.0x
IQR3.6x
Hypergeometric (pmf, cdf)2.4–3.4x
Variance / StdDev2.2x
Skewness2.1x
One-sample t-test1.7x
Two-sample t-test1.6x

Parity (within 1.5x)

Mean, Median, Percentile 50/95, Kolmogorov-Smirnov, Mann-Whitney U, Kendall Tau, Spearman, Beta, Gamma, Student's t, Exponential, Poisson, Uniform, Cauchy (pdf/cdf).


Descriptive Statistics

Descriptive Statistics n=100,000

Other sizes

n=100 n=1,000 n=10,000

Key findings:

  • kstats kurtosis is 4.2x faster — single-pass computation vs multi-pass in Commons
  • kstats mean is 1.4x faster at scale (Neumaier compensated summation)
  • Commons variance/stdDev is ~2x faster (simpler single-pass without compensation)
  • Commons describe() aggregation is ~7x faster (delegates to internal SummaryStatistics)

Quantile Benchmarks

Quantile n=100,000

Other sizes

n=1,000 n=10,000

Key findings:

  • Percentile 50 and 95 are comparable
  • Commons IQR is 3.6x faster (single-pass percentile estimation)

Correlation & Regression

Correlation n=10,000

Other sizes

n=100 n=1,000

Key findings:

  • kstats Pearson correlation is 1.8x faster
  • kstats covariance and linear regression are 1.4–1.5x faster
  • Kendall Tau and Spearman are comparable (both O(n log n))

Hypothesis Tests

Hypothesis Tests n=10,000

Other sizes

n=100 n=1,000

Key findings:

  • kstats ANOVA is 5x faster — avoids per-group distribution object creation
  • kstats chi-squared GOF is 39x faster — direct computation without object allocation
  • Commons t-tests are 2–4x faster — highly optimized TDistribution quantile lookup
  • Kolmogorov-Smirnov is essentially tied

Chi-Squared Independence

Chi-Squared Independence

Key findings:

  • kstats is 3.5–58x faster depending on table size — direct matrix computation vs object allocation overhead in Commons

Probability Distributions

Continuous

Continuous Distributions

Discrete

Discrete Distributions

Key findings:

  • kstats Zipf is orders of magnitude faster — precomputed harmonic sums vs on-the-fly O(N) in Commons
  • kstats LogNormal quantile is 443x faster — closed-form inverse vs iterative numerical solver
  • kstats F, Normal CDF, Chi-Squared, Weibull quantile are 2–3x faster
  • Commons Normal quantile, Binomial PMF, and Hypergeometric are faster (different algorithmic approaches)
  • Most distribution operations are sub-microsecond in both libraries

Regenerating Charts

pip install -r benchmark/charts/requirements.txt
python benchmark/charts/generate_charts.py

Or with an explicit report path:

python benchmark/charts/generate_charts.py benchmark/build/reports/benchmarks/main/<timestamp>/main.json

Charts are saved to benchmark/charts/ as SVG files.