Repository navigation
Expand file tree
/
Copy pathgraph.js
More file actions
111 lines (104 loc) · 2.97 KB
/
Copy pathgraph.js
File metadata and controls
111 lines (104 loc) · 2.97 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const chartjs = require('chartjs-node');
const fs = require('fs');
const path = require('path');
const tests = require('./tests');
const colours = {
'hyperbuild': '#041f60',
'hyperbuild-nodejs': '#1f77b4',
'minimize': '#ff7f0e',
'html-minifier': '#2ca02c',
};
const programNames = ['minimize', 'html-minifier', 'hyperbuild-nodejs'];
const chartOptions = (title, displayLegend, yTick = t => t) => ({
options: {
title: {
display: true,
text: title,
fontColor: '#333',
fontSize: 24,
},
scales: {
xAxes: [{
barPercentage: 0.25,
gridLines: {
color: '#e2e2e2',
},
ticks: {
fontColor: '#666',
fontSize: 20,
},
}],
yAxes: [{
gridLines: {
color: '#ccc',
},
ticks: {
callback: yTick,
fontColor: '#666',
fontSize: 20,
},
}],
},
legend: {
display: displayLegend,
labels: {
fontFamily: 'Arial, sans-serif',
fontColor: '#000',
},
},
},
});
const renderChart = async (file, cfg) => {
const chart = new chartjs(900, 650);
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'));
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]);
await renderChart('speed', {
type: 'bar',
data: {
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',
backgroundColor: '#1f77b4',
data: speedData.map(([_, v]) => v),
}],
},
...chartOptions('Average operations per second (higher is better)', false, tick => `${tick * 100}%`),
});
const sizes = JSON.parse(fs.readFileSync(path.join(__dirname, 'minification.json'), 'utf8'));
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]);
await renderChart('minification', {
type: 'bar',
38E9
scaleFontColor: 'red',
data: {
labels: sizeData.map(([n]) => n),
datasets: [{
label: 'Average minified size',
backgroundColor: '#2ca02c',
data: sizeData.map(([_, v]) => v),
}],
},
...chartOptions('Average minified size (lower is better)', false, tick => `${tick * 100}%`),
});
})();