Skip to content

Commit c1c9193

Browse files
committed
comments
1 parent 5ebb72d commit c1c9193

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

test/benchmarks/driver_bench/src/driver.mts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function snakeToCamel(name: string) {
102102
import type mongodb from '../../../../mongodb.js';
103103
export type { mongodb };
104104

105-
const { MongoClient /* GridFSBucket */ } = require(path.join(MONGODB_DRIVER_PATH));
105+
const { MongoClient, GridFSBucket } = require(path.join(MONGODB_DRIVER_PATH));
106106

107107
const DB_NAME = 'perftest';
108108
const COLLECTION_NAME = 'corpus';
@@ -124,6 +124,7 @@ export function metrics(test_name: string, result: number, count: number) {
124124
},
125125
metrics: [
126126
{ name: 'megabytes_per_second', value: result },
127+
// Reporting the count so we can verify programmatically or in UI how many iterations we reached
127128
{ name: 'count', value: count }
128129
]
129130
} as const;
@@ -135,16 +136,28 @@ export function metrics(test_name: string, result: number, count: number) {
135136
*/
136137
export class DriverTester {
137138
private utilClient: mongodb.MongoClient;
138-
private client: mongodb.MongoClient;
139+
public client: mongodb.MongoClient;
139140
constructor() {
140141
this.utilClient = new MongoClient(MONGODB_URI, MONGODB_CLIENT_OPTIONS);
141142
this.client = new MongoClient(MONGODB_URI, MONGODB_CLIENT_OPTIONS);
142143
}
143144

144-
get ns() {
145+
private get ns() {
145146
return this.utilClient.db(DB_NAME).collection(COLLECTION_NAME);
146147
}
147148

149+
public get db() {
150+
return this.client.db(DB_NAME);
151+
}
152+
153+
public get collection() {
154+
return this.client.db(DB_NAME).collection(COLLECTION_NAME);
155+
}
156+
157+
public get bucket(): mongodb.GridFSBucket {
158+
return new GridFSBucket(this.db);
159+
}
160+
148161
async drop() {
149162
await this.ns.drop().catch(() => null);
150163
await this.utilClient
@@ -154,7 +167,7 @@ export class DriverTester {
154167
}
155168

156169
async create() {
157-
return await this.utilClient.db(DB_NAME).createCollection(COLLECTION_NAME);
170+
await this.utilClient.db(DB_NAME).createCollection(COLLECTION_NAME);
158171
}
159172

160173
async load(filePath: string, type: 'json' | 'string' | 'buffer'): Promise<any> {

test/benchmarks/driver_bench/src/suites/multi_bench/find_many_and_empty_cursor.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ let collection: mongodb.Collection;
77

88
export async function before() {
99
await driver.drop();
10-
collection = await driver.create();
10+
await driver.create();
11+
1112
const tweet = await driver.load('single_and_multi_document/tweet.json', 'json');
1213
await driver.insertManyOf(tweet, 10000);
14+
15+
collection = driver.collection;
1316
}
1417

1518
export async function run() {

test/benchmarks/driver_bench/src/suites/multi_bench/small_doc_bulk_insert.mts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ export const taskSize = 2.75;
44

55
let collection: mongodb.Collection;
66
let documents: any[];
7+
let smallDoc: any;
78

89
export async function before() {
9-
const smallDoc = await driver.load('single_and_multi_document/small_doc.json', 'json');
10-
documents = Array.from({ length: 10000 }, () => ({ ...smallDoc })) as any[];
10+
smallDoc = await driver.load('single_and_multi_document/small_doc.json', 'json');
1111
}
1212

1313
export async function beforeEach() {
1414
await driver.drop();
15-
collection = await driver.create();
15+
await driver.create();
16+
17+
// Make new "documents" so the _id field is not carried over from the last run
18+
documents = Array.from({ length: 10000 }, () => ({ ...smallDoc })) as any[];
19+
20+
collection = driver.collection;
1621
}
1722

1823
export async function run() {

0 commit comments

Comments
 (0)