Skip to content

Commit

Permalink
Merge pull request #365 from snyk/chore/performance-measure-script
Browse files Browse the repository at this point in the history
Chore/performance measure script
  • Loading branch information
shaninja committed Aug 24, 2021
2 parents e51b4f2 + 6ccc040 commit 8e55dd1
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions scripts/scan-performance.ts
@@ -0,0 +1,59 @@
#! /usr/bin/env ts-node

// tslint:disable:no-console

import { scan } from "../lib/scan";

process.on("uncaughtException", (err) => {
console.log("UNCAUGHT EXCEPTION! %s", err);
process.exit(1);
});

const DEFAULT_NUMBER_OF_RUNS = 10;

async function main() {
try {
validateArgs();

const imageToScan = process.argv[2];
const numberOfRuns = Number(process.argv[3]) || DEFAULT_NUMBER_OF_RUNS;
console.log(`scanning ${imageToScan}`);
const startTime = Date.now();

for (let i = 0; i < numberOfRuns; i++) {
console.log(`scan # ${i}`);
await scan({
"app-vulns": true,
path: `docker-archive:${imageToScan}`,
});
}

console.log(
`average time per complete scan: ${(Date.now() - startTime) /
numberOfRuns}`,
);
} catch (error) {
console.log(error);
}
}

function validateArgs() {
if (process.argv.length < 3 || !process.argv[2].endsWith(".tar")) {
throw new Error(
`First argument must be a path to a saved image, .tar file`,
);
}

if (!(process.argv[3] && !isNaN(Number(process.argv[3])))) {
throw new Error(
`Invalid argument '${process.argv[3]}' expected a number (number of runs).`,
);
}
}

main()
.then(() => "Done!" && process.exit(0))
.catch((err) => {
console.log(err);
process.exit(1);
});

0 comments on commit 8e55dd1

Please sign in to comment.