MCPcopy Create free account
hub / github.com/Automattic/mongoose / run

Function run

benchmarks/createDeepNestedDocArray.js:10–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8});
9
10async function run() {
11 await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_benchmark');
12
13 const levels = 12;
14
15 let schema = new mongoose.Schema({ test: { type: String, required: true } });
16 let doc = { test: 'gh-14897' };
17 for (let i = 0; i < levels; ++i) {
18 schema = new mongoose.Schema({ level: Number, subdocs: [schema] });
19 doc = { level: (levels - i), subdocs: [{ ...doc }, { ...doc }] };
20 }
21 const Test = mongoose.model('Test', schema);
22
23 if (!process.env.MONGOOSE_BENCHMARK_SKIP_SETUP) {
24 await Test.deleteMany({});
25 }
26
27 const insertStart = Date.now();
28 await Test.create(doc);
29 const insertEnd = Date.now();
30
31 const results = {
32 'create() time ms': +(insertEnd - insertStart).toFixed(2)
33 };
34
35 console.log(JSON.stringify(results, null, ' '));
36 process.exit(0);
37}

Callers 1

Calls 2

deleteManyMethod · 0.80
createMethod · 0.80

Tested by

no test coverage detected