summaryrefslogtreecommitdiff
path: root/benchmark/bench/render.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/render.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/render.js')
-rw-r--r--benchmark/bench/render.js14
1 files changed, 4 insertions, 10 deletions
diff --git a/benchmark/bench/render.js b/benchmark/bench/render.js
index 449a1056f..aaeb0d022 100644
--- a/benchmark/bench/render.js
+++ b/benchmark/bench/render.js
@@ -6,14 +6,13 @@ import { execaCommand } from 'execa';
import { waitUntilBusy } from 'port-authority';
import { markdownTable } from 'markdown-table';
import { renderFiles } from '../make-project/render-default.js';
+import { calculateStat } from '../make-project/_util.js';
import { astroBin } from './_util.js';
const port = 4322;
export const defaultProject = 'render-default';
-/** @typedef {{ avg: number, stdev: number, max: number }} Stat */
-
/**
* @param {URL} projectDir
* @param {URL} outputFile
@@ -68,22 +67,17 @@ async function benchmarkRenderTime() {
result[pathname].push(renderTime);
}
}
- /** @type {Record<string, Stat>} */
+ /** @type {Record<string, import('./_util.js').Stat>} */
const processedResult = {};
for (const [pathname, times] of Object.entries(result)) {
// From the 100 results, calculate average, standard deviation, and max value
- const avg = times.reduce((a, b) => a + b, 0) / times.length;
- const stdev = Math.sqrt(
- times.map((x) => Math.pow(x - avg, 2)).reduce((a, b) => a + b, 0) / times.length
- );
- const max = Math.max(...times);
- processedResult[pathname] = { avg, stdev, max };
+ processedResult[pathname] = calculateStat(times);
}
return processedResult;
}
/**
- * @param {Record<string, Stat>} result
+ * @param {Record<string, import('./_util.js').Stat>} result
*/
function printResult(result) {
return markdownTable(