New: Decision Runtime — closed-set judgments for Agent OS. Read the guide →
HazelJS LogoHazelJS

HAZELJS

Comparison

HazelJS Stats performance against simple-statistics and jStat

HazelJS Stats was fastest among the three libraries for mean plus sample variance and the Welch t statistic in the 100,000-observation benchmark.

Updated November 28, 2026

Try it locally

Compute the mean, sample variance, and Welch t statistic with HazelJS Stats, simple-statistics, and jStat. Use Node.js 20 or later and an npm registry that serves HazelJS 2.2.0.

Jump to benchmark results

mkdir stats-example
cd stats-example
npm init -y
npm install @hazeljs/​stats@2.2.0 simple-statistics@7.12.1 jstat@1.9.6

Save this as compare.mjs.

import { meanAndVariance, tests } from '@hazeljs/​stats';
import { mean, sampleVariance } from 'simple-statistics';
import jstat from 'jstat';

const { jStat } = jstat;
const a = [1, 2, 3, 4];
const b = [2, 4, 6, 8];

const hazel = meanAndVariance(Float64Array.from(a));
const welch = tests.ttestIndependent(a, b, { equalVariance: false });
const jStatSampleVariance = (values) => jStat.variance(values, true);
const statistic = (meanOf, varianceOf) =>
  (meanOf(a) - meanOf(b)) /​
  Math.sqrt(varianceOf(a) /​ a.length + varianceOf(b) /​ b.length);

console.table({
  'HazelJS Stats': { ...hazel, welchT: welch.statistic },
  'simple-statistics': {
    mean: mean(a),
    variance: sampleVariance(a),
    welchT: statistic(mean, sampleVariance),
  },
  jStat: {
    mean: jStat.mean(a),
    variance: jStatSampleVariance(a),
    welchT: statistic(jStat.mean, jStatSampleVariance),
  },
});

console.log('Full HazelJS Welch test', {
  pValue: welch.pValue,
  degreesOfFreedom: welch.degreesOfFreedom,
});
node compare.mjs

All three rows should show a mean of 2.5, a sample variance of about 1.6667, and a Welch t statistic of about -1.7321. The last line prints the p-value and degrees of freedom from the full HazelJS test. Set b to [4, 3, 2, 1] to try two samples with equal means.

Head-to-head results

On an Apple M3 Max (arm64, Node.js 23.10.0), HazelJS Stats returned the lowest median of the three tested libraries for mean plus sample variance and for the Welch t statistic. On 100,000 observations, mean plus variance took about 30% less time than the next-lowest median, from jStat. Measured results JSON

WorkloadObservationsHazelJS Stats (ms)simple-statistics (ms)jStat (ms)
Mean and sample variance100,0000.1460.2390.210
Welch t statistic100,000 per sample0.2890.4530.397

The Welch row times the statistic alone. It uses the same formula and equivalent inputs in each library. The full test also reports the p-value, degrees of freedom, and other result fields. The harness prepares HazelJS TypedArrays and comparison-library arrays before timing.

Frame query aggregation

Both paths scanned the same 100,000-row CSV and produced a full descriptive summary. Computing the aggregates in DuckDB took about 64% less time than collecting the numeric column and running the summary in JavaScript.

PathMedian (ms)
describeFrame computes aggregates inside DuckDB18.979
collectFrameColumns followed by JavaScript describe52.349

Other Stats workloads

The harness recorded HazelJS timings for these public APIs. These rows have no third-party timing in this run. A dash in the console table marks an unmeasured combination.

WorkloadObservations or settingsHazelJS Stats (ms)
Full descriptive summary100,0007.193
Full Welch test100,000 per sample0.444
Pearson correlation100,000 pairs0.648
OLS regression100,00033.097
Binomial GLM10,00015.159
One-way ANOVA300,000 across three groups8.501
Mann–Whitney U10,000 across two samples2.020
Shapiro–Wilk600.042
Percentile bootstrap1,024, with 199 resamples5.295
Online statistics100,0002.103
Merge online statistics16 precomputed partitions0.003
Online covariance100,000 pairs2.330

Reproduce this benchmark

Each row reports the median of nine warm runs. The harness verifies results outside the timed interval.

npm ci
npm run build -w @hazeljs/​frame -w @hazeljs/​numeric -w @hazeljs/​stats
cd benchmarks/​stats
npm ci
npm start -- 100000

The run writes medians, workload sizes, and runtime information to benchmarks/​stats/​results/​latest.json. Stats package guide

FAQ

What does a dash mean in the benchmark?
A dash marks a library and workload combination that the benchmark did not time.
Does the Welch comparison include p-values?
The head-to-head row computes only the Welch t statistic. The full test, including p-values and degrees of freedom, has a separate HazelJS Stats timing.