aboutsummaryrefslogtreecommitdiff
path: root/benchmark/bench/_util.js
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/bench/_util.js')
-rw-r--r--benchmark/bench/_util.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/benchmark/bench/_util.js b/benchmark/bench/_util.js
new file mode 100644
index 000000000..d9dfe5b19
--- /dev/null
+++ b/benchmark/bench/_util.js
@@ -0,0 +1,32 @@
+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 };
+}
+
+export async function makeProject(name) {
+ console.log('Making project:', name);
+ const projectDir = new URL(`../projects/${name}/`, import.meta.url);
+
+ const makeProjectMod = await import(`../make-project/${name}.js`);
+ await makeProjectMod.run(projectDir);
+
+ console.log('Finished making project:', name);
+ return projectDir;
+}