summaryrefslogtreecommitdiff
path: root/benchmark/bench/_util.js
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2023-07-10 23:43:01 +0800
committerGravatar GitHub <noreply@github.com> 2023-07-10 23:43:01 +0800
commit255dead86fdcc9f744f58a69c0f32ee70dd3ab90 (patch)
treec60e492733f47ac74184e371a84079063005329e /benchmark/bench/_util.js
parent65ecbcb2867030a7e0a9bb65e808fdcb7e430f5a (diff)
downloadastro-255dead86fdcc9f744f58a69c0f32ee70dd3ab90.tar.gz
astro-255dead86fdcc9f744f58a69c0f32ee70dd3ab90.tar.zst
astro-255dead86fdcc9f744f58a69c0f32ee70dd3ab90.zip
Add CLI startup speed benchmark (#7617)
Diffstat (limited to 'benchmark/bench/_util.js')
-rw-r--r--benchmark/bench/_util.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/benchmark/bench/_util.js b/benchmark/bench/_util.js
index b61c79a78..c9108695c 100644
--- a/benchmark/bench/_util.js
+++ b/benchmark/bench/_util.js
@@ -1,3 +1,18 @@
import { createRequire } from 'module';
export const astroBin = createRequire(import.meta.url).resolve('astro');
+
+/** @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 };
+}