-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Performance improvements for `insertMany()`
- Loading branch information
Showing
5 changed files
with
130 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'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 FooSchema = new mongoose.Schema({ foo: String }); | ||
const FooModel = mongoose.model('Foo', FooSchema); | ||
|
||
if (!process.env.MONGOOSE_BENCHMARK_SKIP_SETUP) { | ||
await FooModel.deleteMany({}); | ||
} | ||
|
||
const numDocs = 1500; | ||
const docs = []; | ||
for (let i = 0; i < numDocs; ++i) { | ||
docs.push({ foo: 'test foo ' + i }); | ||
} | ||
|
||
const numIterations = 200; | ||
const insertStart = Date.now(); | ||
for (let i = 0; i < numIterations; ++i) { | ||
await FooModel.insertMany(docs); | ||
} | ||
const insertEnd = Date.now(); | ||
|
||
const results = { | ||
'Average insertMany time ms': +((insertEnd - insertStart) / numIterations).toFixed(2) | ||
}; | ||
|
||
console.log(JSON.stringify(results, null, ' ')); | ||
process.exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters