Created
May 19, 2020 10:32
-
-
Save jayu/9e4c44335e218a0bf482b292a81159d8 to your computer and use it in GitHub Desktop.
Command execution time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cp = require('child_process') | |
const results = [] | |
for (let i = 0; i < 10; i++) { | |
const result = cp.execSync('yarn --cwd app build') | |
const resultString = result.toString() | |
const timeMatch = resultString.match(/\d\d\.\d\ds\./) | |
if (timeMatch === null) { | |
throw new Error('missing time result') | |
} | |
const time = parseFloat(timeMatch[0].replace('s.', '')) | |
console.log(i, 'Time:', time); | |
results.push(time) | |
} | |
const sum = results.reduce((sum, value) => sum + value, 0) | |
console.log('Avg:', (sum/results.length).toFixed(2), 'Max:', Math.max(...results), 'Min:', Math.min(...results)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment