-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathperf.js
More file actions
65 lines (56 loc) · 1.78 KB
/
Copy pathperf.js
File metadata and controls
65 lines (56 loc) · 1.78 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
'use strict';
const { exec, execSync } = require('child_process');
const fs = require('fs');
const TEST_TIME = 10;
const regexp = /.*?(\d+).*\n.*?(\d+).*\n.*?(\d+).*\n.*?(\d+)/;
exec('make perf_xmem && make perf_alloc', function(err) {
if (err) {
console.error('Error occurred while compling: ' + err.message);
process.exit(4);
}
const times = [ 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 ];
const cases = [ './perf_xmem', './perf_alloc' ];
const result = {};
for (let i = 0; i < cases.length; i++) {
console.log('testing `' + cases[i] + '`...');
result[cases[i]] = [];
for (let j = 0; j < times.length; j++) {
console.log(' testing `' + cases[i] + ' ' + times[j] + '`...');
const test = {
times: 0,
alloc: 0,
free: 0,
total: 0,
};
for (let k = 0; k < TEST_TIME; k++) {
console.log(`testing \`${cases[i]} ${times[j]} for ${k} times...\``);
const stdout = execSync(cases[i] + ' ' + times[j]);
const output = regexp.exec(stdout);
test.times += Number(output[1]);
test.alloc += Number(output[2]);
test.free += Number(output[3]);
test.total += Number(output[4]);
console.log(' done.');
}
for (const key in test) {
if (!test.hasOwnProperty(key)) continue;
test[key] /= TEST_TIME;
}
result[cases[i]].push(test);
console.log(' done.');
}
console.log('done.');
}
// eslint-disable-next-line node/prefer-promises/fs
fs.writeFile(
`./perf/report/${Date.now()}.json`,
JSON.stringify(result),
{ encoding: 'utf8' },
function(err) {
if (err) {
console.error('error occurred: ' + err.message);
} else {
console.log('😊 all done!');
}
});
});