summaryrefslogtreecommitdiff
path: root/scripts/memory/index.js
diff options
context:
space:
mode:
authorGravatar natemoo-re <natemoo-re@users.noreply.github.com> 2022-02-18 20:24:55 +0000
committerGravatar GitHub Actions <actions@github.com> 2022-02-18 20:24:55 +0000
commit3c2eee573224813aba81192abac4ebc99e2bdf20 (patch)
tree71d450779c0ba2d227d3ca26f9610a3ba9be78ad /scripts/memory/index.js
parent23783648b61b43f342c3c2c5c0d90996419c936c (diff)
downloadastro-3c2eee573224813aba81192abac4ebc99e2bdf20.tar.gz
astro-3c2eee573224813aba81192abac4ebc99e2bdf20.tar.zst
astro-3c2eee573224813aba81192abac4ebc99e2bdf20.zip
[ci] yarn format
Diffstat (limited to 'scripts/memory/index.js')
-rw-r--r--scripts/memory/index.js42
1 files changed, 24 insertions, 18 deletions
diff --git a/scripts/memory/index.js b/scripts/memory/index.js
index 8beda6e44..2729c7631 100644
--- a/scripts/memory/index.js
+++ b/scripts/memory/index.js
@@ -9,38 +9,42 @@ import prettyBytes from 'pretty-bytes';
const projDir = new URL('./project/', import.meta.url);
function mean(numbers) {
- var total = 0, i;
+ var total = 0,
+ i;
for (i = 0; i < numbers.length; i += 1) {
- total += numbers[i];
+ total += numbers[i];
}
return total / numbers.length;
}
function median(numbers) {
// median of [3, 5, 4, 4, 1, 1, 2, 3] = 3
- var median = 0, numsLen = numbers.length;
+ var median = 0,
+ numsLen = numbers.length;
numbers.sort();
if (
- numsLen % 2 === 0 // is even
+ numsLen % 2 ===
+ 0 // is even
) {
- // average of two middle numbers
- median = (numbers[numsLen / 2 - 1] + numbers[numsLen / 2]) / 2;
- } else { // is odd
- // middle number only
- median = numbers[(numsLen - 1) / 2];
+ // average of two middle numbers
+ median = (numbers[numsLen / 2 - 1] + numbers[numsLen / 2]) / 2;
+ } else {
+ // is odd
+ // middle number only
+ median = numbers[(numsLen - 1) / 2];
}
return median;
}
let config = await loadConfig({
- cwd: fileURLToPath(projDir)
+ cwd: fileURLToPath(projDir),
});
config.buildOptions.experimentalStaticBuild = true;
-const server = await dev(config, { logging: 'error'});
+const server = await dev(config, { logging: 'error' });
// Prime the server so initial memory is created
await fetch(`http://localhost:3000/page-0`);
@@ -53,14 +57,14 @@ function addSize() {
async function run() {
addSize();
- for(let i = 0; i < 100; i++) {
+ for (let i = 0; i < 100; i++) {
let path = `/page-${i}`;
await fetch(`http://localhost:3000${path}`);
}
addSize();
}
-for(let i = 0; i < 100; i++) {
+for (let i = 0; i < 100; i++) {
await run();
}
@@ -69,13 +73,15 @@ let averageOfLastThirty = mean(lastThirthy);
let medianOfAll = median(sizes);
// If the trailing average is higher than the median, see if it's more than 5% higher
-if(averageOfLastThirty > medianOfAll) {
+if (averageOfLastThirty > medianOfAll) {
let percentage = Math.abs(averageOfLastThirty - medianOfAll) / medianOfAll;
- if(percentage > .05) {
- throw new Error(`The average towards the end (${prettyBytes(averageOfLastThirty)}) is more than 5% higher than the median of all runs (${prettyBytes(medianOfAll)}). This tells us that memory continues to grow and a leak is likely.`)
+ if (percentage > 0.05) {
+ throw new Error(
+ `The average towards the end (${prettyBytes(averageOfLastThirty)}) is more than 5% higher than the median of all runs (${prettyBytes(
+ medianOfAll
+ )}). This tells us that memory continues to grow and a leak is likely.`
+ );
}
}
-
-
await server.stop();