Skip to content

Commit 7f11fa5

Browse files
committed
chore(NODE-6721): migrate singlebench tests
1 parent 198fb72 commit 7f11fa5

File tree

6 files changed

+141
-0
lines changed

6 files changed

+141
-0
lines changed

test/benchmarks/driver_bench/src/driver.mts

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ export function metrics(test_name: string, result: number, count: number) {
138138
* For use in setup/teardown mostly.
139139
*/
140140
export class DriverTester {
141+
readonly DB_NAME = DB_NAME;
142+
readonly COLLECTION_NAME = COLLECTION_NAME;
143+
141144
public client: mongodb.MongoClient;
142145
constructor() {
143146
this.client = new MongoClient(MONGODB_URI, MONGODB_CLIENT_OPTIONS);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { driver, type mongodb } from '../../driver.mjs';
2+
3+
export const taskSize = 16.22;
4+
5+
let collection: mongodb.Collection<{ _id: number }>;
6+
7+
export async function before() {
8+
await driver.drop();
9+
await driver.create();
10+
11+
const tweet = await driver.load('single_and_multi_document/tweet.json', 'json');
12+
await driver.insertManyOf(tweet, 10000, true);
13+
14+
collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME);
15+
}
16+
17+
export async function run() {
18+
for (let _id = 0; _id < 10000; ++_id) {
19+
await collection.findOne({ _id });
20+
}
21+
}
22+
23+
export async function after() {
24+
await driver.drop();
25+
await driver.close();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { driver, type mongodb } from '../../driver.mjs';
2+
3+
export const taskSize = 27.31;
4+
5+
let collection: mongodb.Collection;
6+
let documents: Record<string, any>[];
7+
let largeDoc: Record<string, any>;
8+
9+
export async function before() {
10+
largeDoc = await driver.load('single_and_multi_document/large_doc.json', 'json');
11+
}
12+
13+
export async function beforeEach() {
14+
await driver.drop();
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: 10 }, () => ({ ...largeDoc }));
19+
20+
collection = driver.collection;
21+
}
22+
23+
export async function run() {
24+
for (const doc of documents) {
25+
await collection.insertOne(doc);
26+
}
27+
}
28+
29+
export async function after() {
30+
await driver.drop();
31+
await driver.close();
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { driver, type mongodb } from '../../driver.mjs';
2+
3+
// { ping: 1 } is 15 bytes of BSON x 10,000 iterations
4+
export const taskSize = 0.15;
5+
6+
let db: mongodb.Db;
7+
8+
export async function before() {
9+
await driver.drop();
10+
await driver.create();
11+
12+
db = driver.db;
13+
}
14+
15+
export async function run() {
16+
for (let i = 0; i < 10000; ++i) {
17+
await db.command({ ping: 1 });
18+
}
19+
}
20+
21+
export async function after() {
22+
await driver.drop();
23+
await driver.close();
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { driver, type mongodb } from '../../driver.mjs';
2+
3+
// { hello: true } is 13 bytes of BSON x 10,000 iterations
4+
export const taskSize = 0.13;
5+
6+
let db: mongodb.Db;
7+
8+
export async function before() {
9+
await driver.drop();
10+
await driver.create();
11+
12+
db = driver.db;
13+
}
14+
15+
export async function run() {
16+
for (let i = 0; i < 10000; ++i) {
17+
await db.command({ hello: true });
18+
}
19+
}
20+
21+
export async function after() {
22+
await driver.drop();
23+
await driver.close();
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { driver, type mongodb } from '../../driver.mjs';
2+
3+
export const taskSize = 2.75;
4+
5+
let collection: mongodb.Collection;
6+
let documents: Record<string, any>[];
7+
let smallDoc: Record<string, any>;
8+
9+
export async function before() {
10+
smallDoc = await driver.load('single_and_multi_document/small_doc.json', 'json');
11+
}
12+
13+
export async function beforeEach() {
14+
await driver.drop();
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 }));
19+
20+
collection = driver.collection;
21+
}
22+
23+
export async function run() {
24+
for (const doc of documents) {
25+
await collection.insertOne(doc);
26+
}
27+
}
28+
29+
export async function after() {
30+
await driver.drop();
31+
await driver.close();
32+
}

0 commit comments

Comments
 (0)