@dapplion/benchmark
Version:
Ensures that new code does not introduce performance regressions with CI. Tracks:
42 lines (41 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.appendBenchmarkToHistoryAndPrune = appendBenchmarkToHistoryAndPrune;
function appendBenchmarkToHistoryAndPrune(history, newBench, branch, opts) {
if (opts.benchmarksPerBranch) {
limitBenchmarksPerBranch(history, opts.benchmarksPerBranch);
}
if (opts.prune) {
// Prune commits not in current git history
// TODO
}
addBenchmarkToHistory(history, newBench, branch);
}
/**
* Limit num of benchmarks per branch
*/
function limitBenchmarksPerBranch(history, benchmarksPerBranch) {
for (const branchBenchmarks of Object.values(history.benchmarks)) {
const deleteCount = branchBenchmarks.length - benchmarksPerBranch;
if (deleteCount > 0) {
branchBenchmarks.splice(0, deleteCount);
}
}
}
function addBenchmarkToHistory(history, newBench, branch) {
if (history.benchmarks[branch] === undefined) {
history.benchmarks[branch] = [];
}
// Ensure there are no duplicates for the same commit
history.benchmarks[branch] = history.benchmarks[branch].filter((bench) => {
if (bench.commitSha === newBench.commitSha) {
// eslint-disable-next-line no-console
console.log("Deleting previous benchmark for the same commit");
return false;
}
else {
return true;
}
});
history.benchmarks[branch].push(newBench);
}