-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsole-output.js
39 lines (35 loc) · 948 Bytes
/
console-output.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
const opsSecFormatter = Intl.NumberFormat('en-US', {
notation: 'compact',
maximumSignificantDigits: 4
});
const halfScreen = process.stdout.columns ? process.stdout.columns / 2 : 44; // arbitrary number
module.exports = {
info(str) {
console.log(str);
},
start() {
console.log('-'.repeat(halfScreen));
},
end() {
console.log('-'.repeat(halfScreen));
},
step(result) {
console.log(`${result.name}`);
// TODO(rafaelgss): support non-operation method
for (const operation of result.operations) {
const opName = ` ${operation.name}:`;
let spaces = '';
if (opName.length > halfScreen) {
spaces = opName.length + 2;
} else {
spaces = ' '.repeat(halfScreen - opName.length);
}
console.log(
`${opName}${spaces}${opsSecFormatter.format(operation.opsSec)} (${
operation.samples
} samples)`
);
}
},
printResults() {}
};