Skip to content

Commit 31f0117

Browse files
committed
feat: updating benchmark structure
1 parent c685a59 commit 31f0117

19 files changed

+217
-1179
lines changed

benches/suites/buffers/buffer_allocation.ts renamed to benches/buffer_allocation.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import path from 'node:path';
12
import url from 'node:url';
23
import b from 'benny';
3-
import { summaryName, suiteCommon } from '../../utils.js';
4+
import { suiteCommon } from './utils/index.js';
45

5-
const filename = url.fileURLToPath(new URL(import.meta.url));
6+
const filePath = url.fileURLToPath(import.meta.url);
67

78
async function main() {
89
const summary = await b.suite(
9-
summaryName(filename),
10+
path.basename(filePath, path.extname(filePath)),
1011
b.add('Buffer.alloc', () => {
1112
Buffer.alloc(1350);
1213
}),
@@ -42,8 +43,11 @@ async function main() {
4243
return summary;
4344
}
4445

45-
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
46-
void main();
46+
if (import.meta.url.startsWith('file:')) {
47+
const modulePath = url.fileURLToPath(import.meta.url);
48+
if (process.argv[1] === modulePath) {
49+
void main();
50+
}
4751
}
4852

4953
export default main;

benches/index.ts

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,58 @@
1-
#!/usr/bin/env ts-node
1+
#!/usr/bin/env tsx
22

3-
import type { Summary } from 'benny/lib/internal/common-types.js';
4-
import fs from 'fs';
5-
import path from 'path';
3+
import fs from 'node:fs';
4+
import path from 'node:path';
65
import url from 'node:url';
76
import si from 'systeminformation';
8-
import { fsWalk, resultsPath, suitesPath } from './utils.js';
9-
10-
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
11-
console.log('dirname', dirname);
7+
import { benchesPath } from './utils/utils.js';
8+
import buffer_allocation from './buffer_allocation.js';
9+
import stream_1KiB from './stream_1KiB.js';
10+
import stream_1KiB_FFI from './stream_1KiB_FFI.js';
1211

1312
async function main(): Promise<void> {
14-
console.log('mkdir', path.join(dirname, 'results'));
15-
await fs.promises.mkdir(url.pathToFileURL(path.join(dirname, 'results')), {
13+
await fs.promises.mkdir(path.join(benchesPath, 'results'), {
1614
recursive: true,
1715
});
18-
// Running all suites
19-
for await (const suitePath of fsWalk(suitesPath)) {
20-
// Skip over non-ts and non-js files
21-
const ext = path.extname(suitePath);
22-
if (ext !== '.ts' && ext !== '.js') {
23-
continue;
24-
}
25-
const suite: () => Promise<Summary> = (await import(suitePath)).default;
26-
// Skip default exports that are not functions and are not called "main"
27-
// They might be utility files
28-
if (typeof suite === 'function' && suite.name === 'main') {
29-
await suite();
30-
}
31-
}
32-
// Concatenating metrics
33-
const metricsPath = path.join(resultsPath, 'metrics.txt');
34-
await fs.promises.rm(url.pathToFileURL(metricsPath), { force: true });
16+
await buffer_allocation();
17+
await stream_1KiB();
18+
await stream_1KiB_FFI();
19+
const resultFilenames = await fs.promises.readdir(
20+
path.join(benchesPath, 'results'),
21+
);
22+
const metricsFile = await fs.promises.open(
23+
path.join(benchesPath, 'results', 'metrics.txt'),
24+
'w',
25+
);
3526
let concatenating = false;
36-
for await (const metricPath of fsWalk(resultsPath)) {
37-
// Skip over non-metrics files
38-
if (!metricPath.endsWith('_metrics.txt')) {
39-
continue;
27+
for (const resultFilename of resultFilenames) {
28+
if (/.+_metrics\.txt$/.test(resultFilename)) {
29+
const metricsData = await fs.promises.readFile(
30+
path.join(benchesPath, 'results', resultFilename),
31+
);
32+
if (concatenating) {
33+
await metricsFile.write('\n');
34+
}
35+
await metricsFile.write(metricsData);
36+
concatenating = true;
4037
}
41-
const metricData = await fs.promises.readFile(
42-
url.pathToFileURL(metricPath),
43-
);
44-
if (concatenating) {
45-
await fs.promises.appendFile(url.pathToFileURL(metricsPath), '\n');
46-
}
47-
await fs.promises.appendFile(url.pathToFileURL(metricsPath), metricData);
48-
concatenating = true;
4938
}
39+
await metricsFile.close();
5040
const systemData = await si.get({
5141
cpu: '*',
5242
osInfo: 'platform, distro, release, kernel, arch',
5343
system: 'model, manufacturer',
5444
});
55-
console.log('write file', path.join(dirname, 'results', 'system.json'));
5645
await fs.promises.writeFile(
57-
url.pathToFileURL(path.join(dirname, 'results', 'system.json')),
46+
path.join(benchesPath, 'results', 'system.json'),
5847
JSON.stringify(systemData, null, 2),
5948
);
6049
}
6150

62-
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
63-
void main();
51+
if (import.meta.url.startsWith('file:')) {
52+
const modulePath = url.fileURLToPath(import.meta.url);
53+
if (process.argv[1] === modulePath) {
54+
void main();
55+
}
6456
}
6557

6658
export default main;

benches/results/buffers/buffer_allocation.chart.html renamed to benches/results/buffer_allocation.chart.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<meta http-equiv="X-UA-Compatible" />
77
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js"></script>
8-
<title>buffers.buffer_allocation</title>
8+
<title>buffer_allocation</title>
99
<style>
1010
body {
1111
margin: 0;
@@ -28,7 +28,7 @@
2828
</head>
2929
<body>
3030
<div class="container">
31-
<canvas id="chart1742779743420" width="16" height="9"></canvas>
31+
<canvas id="chart1743111766484" width="16" height="9"></canvas>
3232
</div>
3333
<script>
3434
const format = (num) => {
@@ -51,18 +51,18 @@
5151
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
5252
)
5353
}
54-
const ctx1742779743420 = document
55-
.getElementById('chart1742779743420')
54+
const ctx1743111766484 = document
55+
.getElementById('chart1743111766484')
5656
.getContext('2d')
57-
const chart1742779743420 = new Chart(ctx1742779743420, {
57+
const chart1743111766484 = new Chart(ctx1743111766484, {
5858
type: 'bar',
5959
data: {
6060
labels: ["Buffer.alloc","Buffer.allocUnsafe","Buffer.allocUnsafeSlow","Buffer.from subarray","Buffer.copyBytesFrom","Uint8Array","Uint8Array slice"],
6161
datasets: [
6262
{
63-
data: [1370590,5346372,1350702,2741252,676306,1146307,1027805],
64-
backgroundColor: ["hsl(30.768, 85%, 55%)","hsl(120, 85%, 55%)","hsl(30.312000000000005, 85%, 55%)","hsl(61.52400000000001, 85%, 55%)","hsl(15.180000000000007, 85%, 55%)","hsl(25.727999999999998, 85%, 55%)","hsl(23.063999999999997, 85%, 55%)"],
65-
borderColor: ["hsl(30.768, 85%, 55%)","hsl(120, 85%, 55%)","hsl(30.312000000000005, 85%, 55%)","hsl(61.52400000000001, 85%, 55%)","hsl(15.180000000000007, 85%, 55%)","hsl(25.727999999999998, 85%, 55%)","hsl(23.063999999999997, 85%, 55%)"],
63+
data: [938109,4536822,1033223,2772304,664578,942396,967255],
64+
backgroundColor: ["hsl(24.81600000000001, 85%, 55%)","hsl(120, 85%, 55%)","hsl(27.323999999999995, 85%, 55%)","hsl(73.332, 85%, 55%)","hsl(17.580000000000005, 85%, 55%)","hsl(24.923999999999996, 85%, 55%)","hsl(25.583999999999993, 85%, 55%)"],
65+
borderColor: ["hsl(24.81600000000001, 85%, 55%)","hsl(120, 85%, 55%)","hsl(27.323999999999995, 85%, 55%)","hsl(73.332, 85%, 55%)","hsl(17.580000000000005, 85%, 55%)","hsl(24.923999999999996, 85%, 55%)","hsl(25.583999999999993, 85%, 55%)"],
6666
borderWidth: 2,
6767
},
6868
],
@@ -72,7 +72,7 @@
7272
plugins: {
7373
title: {
7474
display: true,
75-
text: 'buffers.buffer_allocation',
75+
text: 'buffer_allocation',
7676
font: { size: 20 },
7777
padding: 20,
7878
},

0 commit comments

Comments
 (0)