Skip to content

Commit

Permalink
chore: add csv parsing script for performance comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Sep 10, 2024
1 parent b2d505f commit 2b66318
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 2 deletions.
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 <dbx-node@mongodb.com>",
"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/**/*"
]
}

0 comments on commit 2b66318

Please sign in to comment.