Improve graphs
This commit is contained in:
parent
9ee904fdc0
commit
ac36db45f7
|
@ -15,6 +15,8 @@ Available as:
|
||||||
|
|
||||||
## Performance
|
## Performance
|
||||||
|
|
||||||
|
Speed and effectiveness of Node.js version compared to other JS minifiers.
|
||||||
|
|
||||||
![Chart showing speed of HTML minifiers](./bench/speed.png) ![Chart showing effectiveness of HTML minifiers](./bench/minification.png)
|
![Chart showing speed of HTML minifiers](./bench/speed.png) ![Chart showing effectiveness of HTML minifiers](./bench/minification.png)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
|
@ -15,7 +15,7 @@ const tests = fs.readdirSync(testsDir).map(name => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const programs = {
|
const programs = {
|
||||||
'hyperbuild-nodejs': content => hyperbuild.minify(Buffer.from(content)),
|
'hyperbuild-nodejs': content => hyperbuild.minify_in_place(Buffer.from(content)),
|
||||||
'html-minifier': content => htmlMinifier.minify(content, {
|
'html-minifier': content => htmlMinifier.minify(content, {
|
||||||
caseSensitive: false,
|
caseSensitive: false,
|
||||||
collapseBooleanAttributes: true,
|
collapseBooleanAttributes: true,
|
||||||
|
@ -67,10 +67,7 @@ const colours = [
|
||||||
borderColor: '#4bc0c0',
|
borderColor: '#4bc0c0',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const renderChart = async (file, title, cfg) => {
|
const chartOptions = (title, displayLegend, yTick = t => t) => ({
|
||||||
const chart = new chartjs(435, 320);
|
|
||||||
await chart.drawChart({
|
|
||||||
...cfg,
|
|
||||||
options: {
|
options: {
|
||||||
title: {
|
title: {
|
||||||
display: true,
|
display: true,
|
||||||
|
@ -91,18 +88,23 @@ const renderChart = async (file, title, cfg) => {
|
||||||
color: '#666',
|
color: '#666',
|
||||||
},
|
},
|
||||||
ticks: {
|
ticks: {
|
||||||
|
callback: yTick,
|
||||||
fontColor: '#222',
|
fontColor: '#222',
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
legend: {
|
legend: {
|
||||||
|
display: displayLegend,
|
||||||
labels: {
|
labels: {
|
||||||
fontFamily: 'Ubuntu, sans-serif',
|
fontFamily: 'Ubuntu, sans-serif',
|
||||||
fontColor: '#000',
|
fontColor: '#000',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const renderChart = async (file, cfg) => {
|
||||||
|
const chart = new chartjs(435, 320);
|
||||||
|
await chart.drawChart(cfg);
|
||||||
await chart.writeImageToFile('image/png', path.join(__dirname, `${file}.png`));
|
await chart.writeImageToFile('image/png', path.join(__dirname, `${file}.png`));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -154,21 +156,21 @@ suite
|
||||||
count: b.count,
|
count: b.count,
|
||||||
ops: b.hz,
|
ops: b.hz,
|
||||||
})).sort((a, b) => a.hz - b.hz);
|
})).sort((a, b) => a.hz - b.hz);
|
||||||
await renderChart('speed', 'Minification speed', {
|
await renderChart('speed', {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: {
|
data: {
|
||||||
labels: speedResults.map(r => r.name),
|
labels: speedResults.map(r => r.name),
|
||||||
datasets: [{
|
datasets: [{
|
||||||
label: 'Operations per second',
|
|
||||||
...colours[0],
|
...colours[0],
|
||||||
data: speedResults.map(r => r.ops),
|
data: speedResults.map(r => r.ops),
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
...chartOptions('Operations per second (higher is better)', false),
|
||||||
});
|
});
|
||||||
|
|
||||||
const testNames = Object.keys(sizes);
|
const testNames = Object.keys(sizes);
|
||||||
const programNames = Object.keys(programs);
|
const programNames = Object.keys(programs);
|
||||||
await renderChart('minification', 'Relative minified HTML file size', {
|
await renderChart('minification', {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
scaleFontColor: 'red',
|
scaleFontColor: 'red',
|
||||||
data: {
|
data: {
|
||||||
|
@ -176,9 +178,10 @@ suite
|
||||||
datasets: programNames.map((program, i) => ({
|
datasets: programNames.map((program, i) => ({
|
||||||
label: program,
|
label: program,
|
||||||
...colours[i],
|
...colours[i],
|
||||||
data: testNames.map(test => sizes[test][program].relative),
|
data: testNames.map(test => sizes[test][program].relative * 100),
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
...chartOptions('Relative minified HTML file size (lower is better)', true, tick => `${tick}%`),
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.run({'async': true});
|
.run({'async': true});
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 34 KiB |
BIN
bench/speed.png
BIN
bench/speed.png
Binary file not shown.
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Loading…
Reference in New Issue