Skip to content

Instantly share code, notes, and snippets.

@AlttiRi
Last active February 15, 2022 12:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AlttiRi/ba7fbabca1953cba012506010aff8ff9 to your computer and use it in GitHub Desktop.
NPM YARN NODE executing start time
console.log(1);
  • Download this as ZIP
  • Run node process-bench.js "node 1.js"
  • Run node process-bench.js "npm start"
  • Run node process-bench.js "yarn start"
{
"name": "start-time-demo",
"version": "2.0.0",
"main": "1.js",
"scripts": {
"start": "node 1.js"
},
"license": "MIT"
}
const {exec} = require("child_process");
const command = process.argv[2];
if (!command) {
console.log("[error] process.argv[2] is empty");
}
const startTime = Date.now();
const proc = exec(command);
console.log(`[exec start][${command}]`, Date.now() - startTime);
proc.stdout.on("data", data => {
console.log("[data]", Date.now() - startTime);
console.log(data);
});
proc.stdout.on("end", () => {
console.log("[exec end]", Date.now() - startTime);
});
proc.on("error", e => console.log("[error][stdout]", e));
proc.stdout.on("error", e => console.log("[error]", e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment