Skip to content

Commit c0aa391

Browse files
authored
Merge pull request #15742 from Kundan-CR7/feat/nested-array-benchmark
Add benchmark for large nested array documents (related to #9588)
2 parents bfe8919 + a978476 commit c0aa391

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

benchmarks/nestedArrayLarge.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
const mongoose = require('../');
4+
5+
run().catch(err => {
6+
console.error(err);
7+
process.exit(-1);
8+
});
9+
10+
async function run() {
11+
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_benchmark');
12+
13+
const bookSchema = new mongoose.Schema({
14+
ticker: String,
15+
asks: [[Number]],
16+
bids: [[Number]],
17+
timestamp: String,
18+
});
19+
20+
const Book = mongoose.model('BookNestedArray', bookSchema);
21+
22+
const doc = { asks: [], bids: [] };
23+
for (let i = 0; i < 10000; ++i) {
24+
doc.asks.push([i]);
25+
doc.bids.push([i]);
26+
}
27+
28+
if (!process.env.MONGOOSE_BENCHMARK_SKIP_SETUP) {
29+
await Book.deleteMany({});
30+
}
31+
32+
const constructStart = Date.now();
33+
for (let i = 0; i < 100; ++i) {
34+
new Book(doc);
35+
}
36+
const constructEnd = Date.now();
37+
38+
const inst = new Book(doc);
39+
const saveStart = Date.now();
40+
await inst.save();
41+
const saveEnd = Date.now();
42+
43+
const results = {
44+
'document construction (100x) ms': +(constructEnd - constructStart).toFixed(2),
45+
'save() time ms': +(saveEnd - saveStart).toFixed(2)
46+
};
47+
48+
console.log(JSON.stringify(results, null, ' '));
49+
process.exit(0);
50+
}

0 commit comments

Comments
 (0)