Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add csv parsing script for performance comparison #21

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"private": true,
"workspaces": [
"packages/bson-bench",
"packages/driver-bench"
"packages/driver-bench",
"packages/metrics"
],
"devDependencies": {
"@tsconfig/node16": "^16.1.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/metrics/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data/*.csv
data/*.json
Empty file added packages/metrics/data/.gitkeep
Empty file.
18 changes: 18 additions & 0 deletions packages/metrics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "metrics",
"version": "1.0.0",
"description": "helpers for parsing performance results",
"module": "./lib/mod.mjs",
"bin": {
"mndb": "./lib/cli.mjs"
},
"scripts": {
"start": "node --disable-warning=ExperimentalWarning --experimental-strip-types src/main.mts"
},
"keywords": [],
"author": "The MongoDB NodeJS Team <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"csv": "^6.3.10"
}
}
21 changes: 21 additions & 0 deletions packages/metrics/src/main.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import fs from 'node:fs';
import stream from 'node:stream/promises';

import * as csv from 'csv';

const NUM_HEADERS = ['base_mean', 'compare_mean', 'percent_change'];
const HEADERS = ['task', 'test', 'measurement', ...NUM_HEADERS];

await stream.pipeline(
fs.createReadStream('./data/Data.csv', 'utf8'),
csv.parse({ columns: true }),
csv.transform(record =>
Object.fromEntries(
Object.entries(record)
.filter(([header]) => HEADERS.includes(header))
.map(([header, value]) => [header, NUM_HEADERS.includes(header) ? Number(value) : value])
)
),
async (source: csv.transformer.Transformer) =>
console.table((await source.toArray()).toSorted((a, b) => a.percent_change - b.percent_change))
);
13 changes: 13 additions & 0 deletions packages/metrics/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"outDir": "lib",
"strict": false,
"verbatimModuleSyntax": true,
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext"
},
"include": [
"src/**/*"
]
}