Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
perf: add createDeepNestedDocArray benchmark re: #14897
  • Loading branch information
vkarpov15 committed Sep 24, 2024
commit 04263295351f32e2b0c08d3ce79c9cd36fdf98ae
37 changes: 37 additions & 0 deletions benchmarks/createDeepNestedDocArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const mongoose = require('../');

run().catch(err => {
console.error(err);
process.exit(-1);
});

async function run() {
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_benchmark');

const levels = 12;

let schema = new mongoose.Schema({ test: { type: String, required: true } });
let doc = { test: 'gh-14897' };
for (let i = 0; i < levels; ++i) {
schema = new mongoose.Schema({ level: Number, subdocs: [schema] });
doc = { level: (levels - i), subdocs: [{ ...doc }, { ...doc }] };
}
const Test = mongoose.model('Test', schema);

if (!process.env.MONGOOSE_BENCHMARK_SKIP_SETUP) {
await Test.deleteMany({});
}

const insertStart = Date.now();
await Test.create(doc);
const insertEnd = Date.now();

const results = {
'create() time ms': +(insertEnd - insertStart).toFixed(2)
};

console.log(JSON.stringify(results, null, ' '));
process.exit(0);
}