-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze_benches.js
executable file
·75 lines (56 loc) · 2.25 KB
/
analyze_benches.js
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
#!/usr/bin/env node
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const stdinBuffer = fs.readFileSync(0, 'utf-8'); // STDIN_FILENO = 0
assert(stdinBuffer);
const bench_path = stdinBuffer.toString().split('\n').filter(x => !!x).slice(-1)[0];
assert(bench_path);
const bench_data = fs.readFileSync(bench_path, 'utf-8');
const bench_config = fs.readFileSync(__dirname + '/build/benches.json', 'utf-8');
const benches = JSON.parse(bench_data);
const config = JSON.parse(bench_config);
const db_read = 25_000_000;
const db_write = 100_000_000;
const output = benches
.map(({ name, reads, writes, weight }) => {
const used_gas = config[name]['used_gas'];
const total_weight = weight + reads * db_read + writes * db_write;
const ratio = parseInt((total_weight / used_gas).toString());
return {
name,
reads,
writes,
weight,
total_weight,
used_gas,
ratio
};
})
.sort((a, b) => b.ratio - a.ratio);
assert(output.length > 0);
console.table(output);
let ratio = output[0].ratio;
// round up ratio
ratio = Math.ceil(ratio / 1_000) * 1_000;
console.log('Ratio', ratio);
const file = `// This file is part of Acala.
// Copyright (C) 2020-2025 Acala Foundation.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pub const RATIO: u64 = ${ratio};
`;
const output_path = process.argv.slice(2)[0];
if (output_path) {
const file_path = path.isAbsolute(output_path) ? output_path : path.resolve(process.cwd(), output_path);
fs.writeFileSync(file_path, file);
}