This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportify.js
63 lines (52 loc) · 1.61 KB
/
reportify.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
62
const fs = require('fs');
const args = process.argv.slice(2);
let file = args[0];
init = () => {
file = JSON.parse(fs.readFileSync(file, { encoding: 'utf8' }));
printBlank();
doPercentages(file);
doTiming(file);
printBar();
printBlank();
}
calcAverage = (arr) => {
return arr.reduce((a,b) => a + b, 0) / arr.length;
}
printBlank = () => {
console.log('');
}
printBar = () => {
console.log('=============');
}
doPercentages = (file) => {
outputs = [];
file.Lambdas.forEach((row) => {
outputs.push( Math.floor(parseInt(row['Statuses']['200'],10)/parseInt(row['TotalReqs'],10)*100));
});
minimum = Math.min(...outputs);
maximum = Math.max(...outputs);
average = calcAverage(outputs);
printBar();
console.log('Total rows: ' + outputs.length);
console.log('Max success: ' + maximum + '%');
console.log('Min success: ' + minimum + '%');
console.log('Avg success: ' + average + '%');
}
doTiming = (file) => {
timeToFirstByte = [];
timeForReq = [];
slowest = [];
fastest = [];
file.Lambdas.forEach((row) => {
timeToFirstByte.push(row['AveTimeToFirst']/1000000000);
timeForReq.push(row['AveTimeForReq']/1000000000);
slowest.push(row['Slowest']/1000000000);
fastest.push(row['Fastest']/1000000000);
});
printBar();
console.log('Avg time to first byte: ' + calcAverage(timeToFirstByte).toFixed(2) + 's');
console.log('Avg time for request: ' + calcAverage(timeForReq).toFixed(2) + 's');
console.log('Avg slowest: ' + calcAverage(slowest).toFixed(2) + 's');
console.log('Avg fastest: ' + calcAverage(fastest).toFixed(2) + 's');
}
init();