2020-01-09 06:40:04 -05:00
|
|
|
const chartjs = require('chartjs-node');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const tests = require('./tests');
|
|
|
|
|
|
|
|
const colours = {
|
|
|
|
'hyperbuild': '#041f60',
|
2020-01-12 01:39:23 -05:00
|
|
|
'hyperbuild-nodejs': '#1f77b4',
|
|
|
|
'minimize': '#ff7f0e',
|
|
|
|
'html-minifier': '#2ca02c',
|
2020-01-09 06:40:04 -05:00
|
|
|
};
|
|
|
|
|
2020-01-12 01:39:23 -05:00
|
|
|
const programNames = ['minimize', 'html-minifier', 'hyperbuild-nodejs'];
|
|
|
|
|
2020-01-09 06:40:04 -05:00
|
|
|
const chartOptions = (title, displayLegend, yTick = t => t) => ({
|
|
|
|
options: {
|
|
|
|
title: {
|
|
|
|
display: true,
|
|
|
|
text: title,
|
2020-01-12 01:39:23 -05:00
|
|
|
fontColor: '#333',
|
2020-01-12 04:32:37 -05:00
|
|
|
fontSize: 24,
|
2020-01-09 06:40:04 -05:00
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
xAxes: [{
|
2020-01-14 05:30:44 -05:00
|
|
|
barPercentage: 0.25,
|
2020-01-09 06:40:04 -05:00
|
|
|
gridLines: {
|
2020-01-12 01:39:23 -05:00
|
|
|
color: '#e2e2e2',
|
2020-01-09 06:40:04 -05:00
|
|
|
},
|
|
|
|
ticks: {
|
2020-01-12 01:39:23 -05:00
|
|
|
fontColor: '#666',
|
2020-01-12 04:32:37 -05:00
|
|
|
fontSize: 20,
|
2020-01-09 06:40:04 -05:00
|
|
|
},
|
|
|
|
}],
|
|
|
|
yAxes: [{
|
|
|
|
gridLines: {
|
2020-01-12 01:39:23 -05:00
|
|
|
color: '#ccc',
|
2020-01-09 06:40:04 -05:00
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
callback: yTick,
|
2020-01-12 01:39:23 -05:00
|
|
|
fontColor: '#666',
|
2020-01-12 04:32:37 -05:00
|
|
|
fontSize: 20,
|
2020-01-09 06:40:04 -05:00
|
|
|
},
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
display: displayLegend,
|
|
|
|
labels: {
|
2020-01-12 01:39:23 -05:00
|
|
|
fontFamily: 'Arial, sans-serif',
|
2020-01-09 06:40:04 -05:00
|
|
|
fontColor: '#000',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const renderChart = async (file, cfg) => {
|
2020-01-12 04:32:37 -05:00
|
|
|
const chart = new chartjs(900, 650);
|
2020-01-09 06:40:04 -05:00
|
|
|
await chart.drawChart(cfg);
|
|
|
|
await chart.writeImageToFile('image/png', path.join(__dirname, `${file}.png`));
|
|
|
|
};
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
const testNames = tests.map(t => t.name).sort();
|
|
|
|
|
|
|
|
const speedResults = JSON.parse(fs.readFileSync(path.join(__dirname, 'speed.json'), 'utf8'));
|
2020-01-12 01:39:23 -05:00
|
|
|
const speedData = programNames.map(program => [
|
|
|
|
program,
|
|
|
|
testNames
|
|
|
|
// Get OP/s for each test.
|
|
|
|
.map(test => speedResults[test][program] / speedResults[test]['hyperbuild-nodejs'])
|
|
|
|
// Sum all test OP/s.
|
|
|
|
.reduce((sum, c) => sum + c)
|
|
|
|
// Divide by tests count to get average OP/s.
|
|
|
|
/ testNames.length,
|
|
|
|
]).sort((a, b) => a[1] - b[1]);
|
2020-01-09 06:40:04 -05:00
|
|
|
await renderChart('speed', {
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
2020-01-12 01:39:23 -05:00
|
|
|
labels: speedData.map(([n]) => n),
|
|
|
|
// Node.js version is close enough to Rust version, so leave out Rust results.
|
|
|
|
// Include it this if this situation changes.
|
|
|
|
datasets: [{
|
|
|
|
label: 'Average relative OP/s',
|
2020-01-12 01:48:00 -05:00
|
|
|
backgroundColor: '#1f77b4',
|
2020-01-12 01:39:23 -05:00
|
|
|
data: speedData.map(([_, v]) => v),
|
|
|
|
}],
|
2020-01-09 06:40:04 -05:00
|
|
|
},
|
2020-01-12 01:39:23 -05:00
|
|
|
...chartOptions('Average operations per second (higher is better)', false, tick => `${tick * 100}%`),
|
2020-01-09 06:40:04 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const sizes = JSON.parse(fs.readFileSync(path.join(__dirname, 'minification.json'), 'utf8'));
|
2020-01-12 01:39:23 -05:00
|
|
|
const sizeData = programNames.map(program => [
|
|
|
|
program,
|
|
|
|
testNames
|
|
|
|
.map(test => sizes[test][program].relative)
|
|
|
|
.reduce((sum, c) => sum + c)
|
|
|
|
/ testNames.length,
|
|
|
|
]).sort((a, b) => b[1] - a[1]);
|
2020-01-09 06:40:04 -05:00
|
|
|
await renderChart('minification', {
|
|
|
|
type: 'bar',
|
|
|
|
scaleFontColor: 'red',
|
|
|
|
data: {
|
2020-01-12 01:39:23 -05:00
|
|
|
labels: sizeData.map(([n]) => n),
|
|
|
|
datasets: [{
|
|
|
|
label: 'Average minified size',
|
2020-01-12 01:48:00 -05:00
|
|
|
backgroundColor: '#2ca02c',
|
2020-01-12 01:39:23 -05:00
|
|
|
data: sizeData.map(([_, v]) => v),
|
|
|
|
}],
|
2020-01-09 06:40:04 -05:00
|
|
|
},
|
2020-01-12 01:39:23 -05:00
|
|
|
...chartOptions('Average minified size (lower is better)', false, tick => `${tick * 100}%`),
|
2020-01-09 06:40:04 -05:00
|
|
|
});
|
|
|
|
})();
|