summaryrefslogtreecommitdiff
path: root/benchmark/bench/_util.js
blob: 23c4726046bc05461545f15a3ca855a858e23486 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { createRequire } from 'node:module';
import path from 'node:path';

const astroPkgPath = createRequire(import.meta.url).resolve('astro/package.json');

export const astroBin = path.resolve(astroPkgPath, '../astro.js');

/** @typedef {{ avg: number, stdev: number, max: number }} Stat */

/**
 * @param {number[]} numbers
 * @returns {Stat}
 */
export function calculateStat(numbers) {
	const avg = numbers.reduce((a, b) => a + b, 0) / numbers.length;
	const stdev = Math.sqrt(
		numbers.map((x) => Math.pow(x - avg, 2)).reduce((a, b) => a + b, 0) / numbers.length
	);
	const max = Math.max(...numbers);
	return { avg, stdev, max };
}