Skip to content

Commit ad371c2

Browse files
add in more sensitive/granular tests - can revert if needed
1 parent 68b6ba6 commit ad371c2

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

results.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"info": {
4+
"test_name": "findManyAndToArrayOld",
5+
"tags": [
6+
"js-bson"
7+
]
8+
},
9+
"metrics": [
10+
{
11+
"name": "megabytes_per_second",
12+
"value": 92.01875393495698
13+
}
14+
]
15+
}
16+
]

t.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as fs from 'fs/promises';
2+
3+
import { MongoClient } from './lib/index.js';
4+
5+
const client = await MongoClient.connect('mongodb://localhost/');
6+
const cursor = client.db('test').aggregate([
7+
{
8+
$documents: [
9+
JSON.parse(
10+
await fs.readFile(
11+
'test/benchmarks/driverBench/spec/single_and_multi_document/tweet.json',
12+
'utf8'
13+
)
14+
)
15+
]
16+
},
17+
{
18+
$set: {
19+
field: {
20+
$reduce: {
21+
input: [...Array(20).keys()],
22+
initialValue: [0],
23+
in: { $concatArrays: ['$$value', '$$value'] }
24+
}
25+
}
26+
}
27+
},
28+
{ $unwind: '$field' },
29+
{ $limit: 1000000 }
30+
]);
31+
32+
await cursor.toArray();
33+
await client.close();

test/benchmarks/mongoBench/suites/multiBench.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,86 @@ function makeMultiBench(suite) {
155155
})
156156
.teardown(dropDb)
157157
.teardown(disconnectClient)
158+
).benchmark('aggregateAMillionDocuments', benchmark =>
159+
benchmark
160+
.taskSize(16)
161+
.setup(makeMakeClient(mongodbDriver))
162+
.setup(connectClient)
163+
.setup(initDb)
164+
.setup(dropDb)
165+
.task(async function () {
166+
await this.db
167+
.aggregate([
168+
{ $documents: [{}] },
169+
{
170+
$set: {
171+
field: {
172+
$reduce: {
173+
input: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
174+
initialValue: [0],
175+
in: { $concatArrays: ['$$value', '$$value'] }
176+
}
177+
}
178+
}
179+
},
180+
{ $unwind: '$field' },
181+
{ $limit: 1000000 }
182+
])
183+
.toArray();
184+
})
185+
.teardown(dropDb)
186+
.teardown(disconnectClient)
187+
)
188+
.benchmark('aggregateAMillionTweets', benchmark =>
189+
benchmark
190+
.taskSize(1500)
191+
.setup(makeLoadJSON('tweet.json'))
192+
.setup(makeMakeClient(mongodbDriver))
193+
.setup(connectClient)
194+
.setup(initDb)
195+
.setup(dropDb)
196+
.task(async function () {
197+
await this.db
198+
.aggregate([
199+
{ $documents: [this.doc] },
200+
{
201+
$set: {
202+
id: {
203+
$reduce: {
204+
input: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
205+
initialValue: [0],
206+
in: { $concatArrays: ['$$value', '$$value'] }
207+
}
208+
}
209+
}
210+
},
211+
{ $unwind: '$id' },
212+
{ $limit: 1000000 }
213+
])
214+
.toArray();
215+
})
216+
.teardown(dropDb)
217+
.teardown(disconnectClient)
218+
)
219+
.benchmark('findManyAndEmptyAMillionCursor', benchmark =>
220+
benchmark
221+
.taskSize(16.22)
222+
.setup(makeMakeClient(mongodbDriver))
223+
.setup(connectClient)
224+
.setup(initDb)
225+
.setup(dropDb)
226+
.setup(initCollection)
227+
.setup(async function () {
228+
await this.collection.insertMany(Array.from({ length: 1_000_000 }, () => ({ field: 0 })));
229+
})
230+
.task(async function findManyAndEmptyCursor() {
231+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
232+
for await (const _ of this.collection.find({})) {
233+
// do nothing
234+
}
235+
})
236+
.teardown(dropDb)
237+
.teardown(disconnectClient)
158238
);
159239
}
160240

0 commit comments

Comments
 (0)