[ci] yarn format
This commit is contained in:
parent
23783648b6
commit
3c2eee5732
2 changed files with 25 additions and 19 deletions
|
@ -9,38 +9,42 @@ import prettyBytes from 'pretty-bytes';
|
||||||
const projDir = new URL('./project/', import.meta.url);
|
const projDir = new URL('./project/', import.meta.url);
|
||||||
|
|
||||||
function mean(numbers) {
|
function mean(numbers) {
|
||||||
var total = 0, i;
|
var total = 0,
|
||||||
|
i;
|
||||||
for (i = 0; i < numbers.length; i += 1) {
|
for (i = 0; i < numbers.length; i += 1) {
|
||||||
total += numbers[i];
|
total += numbers[i];
|
||||||
}
|
}
|
||||||
return total / numbers.length;
|
return total / numbers.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function median(numbers) {
|
function median(numbers) {
|
||||||
// median of [3, 5, 4, 4, 1, 1, 2, 3] = 3
|
// 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();
|
numbers.sort();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
numsLen % 2 === 0 // is even
|
numsLen % 2 ===
|
||||||
|
0 // is even
|
||||||
) {
|
) {
|
||||||
// average of two middle numbers
|
// average of two middle numbers
|
||||||
median = (numbers[numsLen / 2 - 1] + numbers[numsLen / 2]) / 2;
|
median = (numbers[numsLen / 2 - 1] + numbers[numsLen / 2]) / 2;
|
||||||
} else { // is odd
|
} else {
|
||||||
// middle number only
|
// is odd
|
||||||
median = numbers[(numsLen - 1) / 2];
|
// middle number only
|
||||||
|
median = numbers[(numsLen - 1) / 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
return median;
|
return median;
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = await loadConfig({
|
let config = await loadConfig({
|
||||||
cwd: fileURLToPath(projDir)
|
cwd: fileURLToPath(projDir),
|
||||||
});
|
});
|
||||||
|
|
||||||
config.buildOptions.experimentalStaticBuild = true;
|
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
|
// Prime the server so initial memory is created
|
||||||
await fetch(`http://localhost:3000/page-0`);
|
await fetch(`http://localhost:3000/page-0`);
|
||||||
|
@ -53,14 +57,14 @@ function addSize() {
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
addSize();
|
addSize();
|
||||||
for(let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
let path = `/page-${i}`;
|
let path = `/page-${i}`;
|
||||||
await fetch(`http://localhost:3000${path}`);
|
await fetch(`http://localhost:3000${path}`);
|
||||||
}
|
}
|
||||||
addSize();
|
addSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
await run();
|
await run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,13 +73,15 @@ let averageOfLastThirty = mean(lastThirthy);
|
||||||
let medianOfAll = median(sizes);
|
let medianOfAll = median(sizes);
|
||||||
|
|
||||||
// If the trailing average is higher than the median, see if it's more than 5% higher
|
// 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;
|
let percentage = Math.abs(averageOfLastThirty - medianOfAll) / medianOfAll;
|
||||||
if(percentage > .05) {
|
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.`)
|
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();
|
await server.stop();
|
||||||
|
|
|
@ -2,7 +2,7 @@ import fs from 'fs';
|
||||||
|
|
||||||
const pages = new URL('./project/src/pages/', import.meta.url);
|
const pages = new URL('./project/src/pages/', import.meta.url);
|
||||||
|
|
||||||
for(let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
let content = `---
|
let content = `---
|
||||||
const i = ${i};
|
const i = ${i};
|
||||||
---
|
---
|
||||||
|
|
Loading…
Reference in a new issue