-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunAll.js
42 lines (36 loc) · 1.65 KB
/
runAll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const si = require('systeminformation')
const fs = require('fs')
const path = require('path')
const execSync = require('child_process').execSync
const esc = String.fromCharCode(27)
async function runAll() {
const info = await si.cpu()
console.log('-'.repeat(50))
console.log(`${info.manufacturer} ${info.brand} ${info.cores} cores @${info.speed}GHz`)
console.log('-'.repeat(50))
const entries = fs.readdirSync(__dirname)
.filter(entry => !entry.match(/^\./) && fs.lstatSync(path.join(__dirname, entry)).isDirectory())
entries.forEach(prepare)
const results = entries.map(run).filter(a => a).sort((a, b) => a.time - b.time)
console.log(esc + '[' + entries.length + 'A')
results.forEach(entry => console.log(entry.info.padEnd(35) + entry.time.padStart(15)))
}
function prepare(language) {
if (fs.existsSync(path.join(__dirname, language, 'prepare.sh'))) {
console.log(esc + '[KCompiling ' + language + ' ...')
execSync(path.join(__dirname, language, 'prepare.sh'))
console.log(esc + '[A' + esc + '[K' + esc + '[A')
}
}
function run(language) {
if (fs.existsSync(path.join(__dirname, language, 'run.sh'))) {
console.log('Running ' + language + ' ...')
const result = execSync(path.join(__dirname, language, 'run.sh')).toString().split('\n').filter(line => line.match('Elapsed')).pop()
const components = result.split(' ')
const time = '' + parseFloat(components.pop()).toFixed(3)
const info = components.filter(word => word !== 'Elapsed').join(' ')
console.log(esc + '[A' + info.padEnd(35) + time.padStart(15))
return {info, time}
}
}
runAll()