Improve graphs

This commit is contained in:
Wilson Lin 2020-01-05 15:18:53 +11:00
parent 9ee904fdc0
commit ac36db45f7
4 changed files with 43 additions and 38 deletions

View File

@ -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

View File

@ -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,42 +67,44 @@ 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); options: {
await chart.drawChart({ title: {
...cfg, display: true,
options: { text: title,
title: { },
display: true, scales: {
text: title, xAxes: [{
}, barPercentage: 0.5,
scales: { gridLines: {
xAxes: [{ color: '#ccc',
barPercentage: 0.5,
gridLines: {
color: '#ccc',
},
ticks: {
fontColor: '#222',
},
}],
yAxes: [{
gridLines: {
color: '#666',
},
ticks: {
fontColor: '#222',
},
}],
},
legend: {
labels: {
fontFamily: 'Ubuntu, sans-serif',
fontColor: '#000',
}, },
ticks: {
fontColor: '#222',
},
}],
yAxes: [{
gridLines: {
color: '#666',
},
ticks: {
callback: yTick,
fontColor: '#222',
},
}],
},
legend: {
display: displayLegend,
labels: {
fontFamily: 'Ubuntu, sans-serif',
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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB