Add --profile argument to harness.mjs for measuring and reporting elapsed time.

This commit is contained in:
David Anson 2023-08-28 21:24:36 -07:00
parent 3099a98b51
commit 87fda39df8

View file

@ -24,12 +24,33 @@ function consoleLogTokens(tokens, depth = 0) {
}
}
const files = process.argv.slice(2);
let profile = false;
let count = 1;
const files = process.argv.slice(2).filter((arg) => {
if (arg === "--profile") {
profile = true;
count = 1000;
return false;
}
return true;
});
for (const file of files) {
const content = await readFile(file, "utf8");
consoleLogTokens(parse(content));
const results = await markdownlint({
"files": [ file ]
});
console.dir(results, { "depth": null });
if (!profile) {
const content = await readFile(file, "utf8");
consoleLogTokens(parse(content));
}
let results = null;
performance.mark("profile-start");
for (let i = 0; i < count; i++) {
results = await markdownlint({
"files": [ file ]
});
}
const measure = performance.measure("profile", "profile-start");
if (profile) {
console.log(Math.round(measure.duration));
} else {
console.dir(results, { "depth": null });
}
}