Skip to content

Commit 2cfbb88

Browse files
Make the output more readable
1 parent 1d84381 commit 2cfbb88

5 files changed

Lines changed: 39 additions & 38 deletions

File tree

README.md

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
1-
# Speed Measure Plugin
1+
<div align="center"><h1>Speed Measure Plugin</h1></div>
2+
<br>
23

34
This plugin measures your webpack build speed, giving an output like this:
45

5-
```
6-
----------------------------
7-
General output time took 1.01 minutes
8-
9-
IgnorePlugin took 0.62 seconds
10-
ForceCaseSensitivityPlugin took 20.27 seconds
11-
SpriteLoaderPlugin took 30 milliseconds
12-
ExtractTextPlugin took 9.44 seconds
13-
DefinePlugin took 1 milliseconds
14-
15-
thread-loader, and
16-
babel-loader took 0.56 minutes
17-
Med = 401 milliseconds,
18-
x̄ = 1.08 seconds,
19-
σ = 0.57 seconds,
20-
range = (268 milliseconds, 2.49 seconds),
21-
n = 247
22-
file-loader took 7.11 seconds
23-
Med = 1.41 seconds,
24-
x̄ = 1.26 seconds,
25-
σ = 436 milliseconds,
26-
range = (340 milliseconds, 2.02 seconds),
27-
n = 29
28-
----------------------------
29-
```
6+
![Preview of Speed Measure Plugin's output](preview.png)
307

318
# Getting Started
329

colours.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const green = "\x1b[32m";
2+
const yellow = "\x1b[33m";
3+
const red = "\x1b[31m";
4+
const bold = "\x1b[1m";
5+
const end = "\x1b[0m";
6+
7+
module.exports.b = (text, time) => {
8+
let colour;
9+
if (time >= 0) colour = green;
10+
if (time > 2000) colour = yellow;
11+
if (time > 10000) colour = red;
12+
13+
return (colour || "") + bold + text + end;
14+
};
15+
16+
module.exports.stripColours = text => text.replace(/\x1b\[[0-9]+m/g, "");

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
getPluginsOutput,
88
getLoadersOutput,
99
} = require("./output");
10+
const { stripColours } = require("./colours");
1011

1112
module.exports = class SpeedMeasurePlugin {
1213
constructor(options) {
@@ -99,10 +100,11 @@ module.exports = class SpeedMeasurePlugin {
99100

100101
const output = this.getOutput();
101102
if (this.options.outputTarget) {
103+
const strippedOutput = stripColours(output);
102104
const writeMethod = fs.existsSync(this.options.outputTarget)
103105
? fs.appendFile
104106
: fs.writeFile;
105-
writeMethod(this.options.outputTarget, output + "\n", err => {
107+
writeMethod(this.options.outputTarget, strippedOutput + "\n", err => {
106108
if (err) throw err;
107109
console.log("Outputted timing info to " + this.options.outputTarget);
108110
});

output.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { b } = require("./colours");
12
const { groupBy, getAverages, getTotalActiveTime } = require("./utils");
23

34
const humanTime = ms => {
@@ -11,22 +12,25 @@ const humanTime = ms => {
1112
return ms.toFixed(0) + " milliseconds";
1213
};
1314

14-
const b = text => "\x1b[1m" + text + "\x1b[0m";
15-
const bb = text => "\x1b[1m\x1b[32m" + text + "\x1b[0m";
16-
1715
module.exports.getHumanOutput = outputObj => {
1816
const delim = "----------------------------";
1917
let output = delim + "\n";
2018

2119
if (outputObj.misc) {
2220
output +=
23-
"General output time took " + bb(humanTime(outputObj.misc.compileTime));
21+
"General output time took " +
22+
b(humanTime(outputObj.misc.compileTime), outputObj.misc.compileTime);
2423
output += "\n\n";
2524
}
2625
if (outputObj.plugins) {
2726
Object.keys(outputObj.plugins).forEach(pluginName => {
2827
output +=
29-
b(pluginName) + " took " + bb(humanTime(outputObj.plugins[pluginName]));
28+
b(pluginName) +
29+
" took " +
30+
b(
31+
humanTime(outputObj.plugins[pluginName]),
32+
outputObj.plugins[pluginName]
33+
);
3034
output += "\n";
3135
});
3236
output += "\n";
@@ -36,22 +40,24 @@ module.exports.getHumanOutput = outputObj => {
3640
output +=
3741
loaderObj.loaders.map(b).join(", and \n") +
3842
" took " +
39-
bb(humanTime(loaderObj.activeTime));
43+
b(humanTime(loaderObj.activeTime), loaderObj.activeTime);
4044
output += "\n";
41-
output += " Med = " + humanTime(loaderObj.averages.median) + ",\n";
42-
output += " x̄ = " + humanTime(loaderObj.averages.mean) + ",\n";
45+
output +=
46+
" mean = " + humanTime(loaderObj.averages.median) + ",\n";
47+
output +=
48+
" median = " + humanTime(loaderObj.averages.mean) + ",\n";
4349
if (typeof loaderObj.averages.variance === "number")
4450
output +=
45-
" σ = " +
51+
" s.d = " +
4652
humanTime(Math.sqrt(loaderObj.averages.variance)) +
4753
", \n";
4854
output +=
49-
" range = (" +
55+
" range = (" +
5056
humanTime(loaderObj.averages.range.start) +
5157
", " +
5258
humanTime(loaderObj.averages.range.end) +
5359
"), \n";
54-
output += " n = " + loaderObj.averages.dataPoints + "\n";
60+
output += " module count = " + loaderObj.averages.dataPoints + "\n";
5561
});
5662
}
5763

preview.png

90.4 KB
Loading

0 commit comments

Comments
 (0)