-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgreedyMin-ensemble.js
61 lines (56 loc) · 2.03 KB
/
greedyMin-ensemble.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const chalk = require('chalk')
const { execFileSync } = require('child_process');
let args = process.argv.slice(2);
let pathToFile = args[1]
// let alpha = parseFloat(args[2])
let runs = parseFloat(args[0])
let totalRunningTime = 0
let cummulativeReducedSetSize = 0
function convertToMs(time){
// minutesR = new RegExp("[0-9]*m ","g");
// secondsR = new RegExp("[0-9]*s ","g");
// millisecondsR = new RegExp("[0-9]*ms","g");
// minutes = time.match(minutesR)
// seconds = time.match(secondsR)
// milliseconds = time.match(millisecondsR)
another = new RegExp("[0-9]+","g");
match = time.match(another)
minutes = parseFloat(match[0])
seconds = parseFloat(match[1])
milliseconds = parseFloat(match[2])
// console.log(minutes,seconds,milliseconds)
return minutes*60*1000 + seconds*1000 + milliseconds
}
function runScript(pathToFile,callback) {
const output = execFileSync("node",["greedyMin.js",pathToFile])
console.log(output.toString())
lines = output.toString().split("\n");
for (let line of lines){
if (line.includes("Reduced set Size :")){
size = parseFloat(line.split(":")[1])
cummulativeReducedSetSize += size
}
regex = new RegExp("[0-9]*m [0-9]*s [0-9]*ms","g");
match = line.match(regex);
if(match){
timeInMs = convertToMs(match.toString());
totalRunningTime += timeInMs;
}
}
}
// var start = new Date().getTime();
for (var i=0; i<runs; i++){
console.log(`${chalk.green("Executing Run#"+(i+1))}`)
runScript(pathToFile,function (err) {
if (err) throw err;
});
}
// var end = new Date().getTime();
// var time = end - start;
time = Math.round(totalRunningTime/runs,2)
var seconds = Math.floor(time/1000);
var minutes = Math.floor(seconds/60);
averageTSSize = cummulativeReducedSetSize/runs
averageTSSize = averageTSSize.toFixed(2)
console.log(`${chalk.bgMagenta("Average Execution Time = "+minutes+"m "+ (seconds-minutes*60)+"s " + (time - seconds*1000)+ "ms" + "("+time+" ms)")}`)
console.log(`${chalk.bgMagenta("Average reduced test set size = "+averageTSSize)}`)