Skip to content

Instantly share code, notes, and snippets.

@jayu
Created May 19, 2020 10:32
Show Gist options
  • Save jayu/9e4c44335e218a0bf482b292a81159d8 to your computer and use it in GitHub Desktop.
Save jayu/9e4c44335e218a0bf482b292a81159d8 to your computer and use it in GitHub Desktop.
Command execution time
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