Skip to content

Commit

Permalink
refactor: perf script
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Dec 26, 2021
1 parent cbd1e9e commit 3feb343
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
22 changes: 13 additions & 9 deletions scripts/perf.js
@@ -1,6 +1,6 @@
/* global gc */

const { readFileSync, writeFileSync } = require('fs');
const { promises } = require('fs');
const path = require('path');
const colorette = require('colorette');
const prettyBytes = require('pretty-bytes');
Expand Down Expand Up @@ -89,7 +89,7 @@ async function calculatePrintAndPersistTimings(config, existingTimings) {
}
const averageTimings = getAverage(timings, numberOfRunsToAverage, numberOfDiscardedResults);
printMeasurements(averageTimings, existingTimings);
if (Object.keys(existingTimings).length === 0) persistTimings(averageTimings);
if (Object.keys(existingTimings).length === 0) await persistTimings(averageTimings);
}

async function buildAndGetTimings(config) {
Expand Down Expand Up @@ -135,9 +135,9 @@ function clearLines(numberOfLines) {
console.info('\33[A' + '\33[2K\33[A'.repeat(numberOfLines));
}

function getExistingTimings() {
async function getExistingTimings() {
try {
const timings = JSON.parse(readFileSync(perfFile, 'utf8'));
const timings = JSON.parse(await promises.readFile(perfFile, 'utf8'));
console.info(
colorette.bold(
`Comparing with ${colorette.cyan(perfFile)}. Delete this file to create a new base line.`
Expand All @@ -149,9 +149,9 @@ function getExistingTimings() {
}
}

function persistTimings(timings) {
async function persistTimings(timings) {
try {
writeFileSync(perfFile, JSON.stringify(timings, null, 2), 'utf8');
await promises.writeFile(perfFile, JSON.stringify(timings, null, 2), 'utf8');
console.info(
colorette.bold(
`Saving performance information to new reference file ${colorette.cyan(perfFile)}.`
Expand Down Expand Up @@ -198,6 +198,10 @@ function getFormattedMemory(currentMemory, persistedMemory = currentMemory) {
return color(formattedMemory);
}

loadPerfConfig().then(async config =>
calculatePrintAndPersistTimings(config, await getExistingTimings())
);
async function start() {
const config = await loadPerfConfig();
const timings = await getExistingTimings();
await calculatePrintAndPersistTimings(config, timings);
}

start();
1 change: 0 additions & 1 deletion test/watch/index.js
Expand Up @@ -1362,7 +1362,6 @@ describe('rollup.watch', () => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
// sometimes the watcher is triggered during the initial run
watchChangeIds.clear();

await Promise.all(watchFiles.map(file_2 => promises.writeFile(file_2, 'changed')));
},
'START',
Expand Down

0 comments on commit 3feb343

Please sign in to comment.