Skip to content

Commit 23fa88e

Browse files
committed
benchmarks: add nestedArrayLarge benchmark to reproduce #9588 scenario
1 parent dfa12ca commit 23fa88e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

benchmarks/nestedArrayLarge.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
const mongoose = require('../');
4+
const Benchmark = require('benchmark');
5+
6+
const { Schema } = mongoose;
7+
8+
run().catch(err => {
9+
console.error(err);
10+
process.exit(1);
11+
});
12+
13+
async function run() {
14+
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_benchmark');
15+
16+
const bookSchema = new Schema({
17+
ticker: String,
18+
asks: [[Number]],
19+
bids: [[Number]],
20+
timestamp: String,
21+
});
22+
23+
const Book = mongoose.model('BookNestedArray', bookSchema);
24+
25+
let doc = { asks: [], bids: [] };
26+
for (let i = 0; i < 10000; ++i) {
27+
doc.asks.push([i]);
28+
doc.bids.push([i]);
29+
}
30+
31+
const suite = new Benchmark.Suite();
32+
33+
suite
34+
.add('BookNestedArray document construction', function () {
35+
new Book(doc);
36+
})
37+
.on('cycle', function(evt) {
38+
if (process.env.MONGOOSE_DEV || process.env.PULL_REQUEST) {
39+
console.log(String(evt.target));
40+
}
41+
})
42+
.run();
43+
44+
await mongoose.disconnect();
45+
}

0 commit comments

Comments
 (0)