-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'automattic/master'
- Loading branch information
Showing
86 changed files
with
2,054 additions
and
1,504 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,72 @@ | ||
'use strict'; | ||
|
||
const get = require('../lib/helpers/get'); | ||
|
||
let obj; | ||
|
||
// Single string | ||
obj = {}; | ||
|
||
let start = Date.now(); | ||
for (let i = 0; i < 10000000; ++i) { | ||
get(obj, 'test', null); | ||
} | ||
console.log('Single string', Date.now() - start); | ||
|
||
// Array of length 1 | ||
obj = {}; | ||
start = Date.now(); | ||
let arr = ['test']; | ||
for (let i = 0; i < 10000000; ++i) { | ||
get(obj, arr, null); | ||
} | ||
console.log('Array of length 1', Date.now() - start); | ||
|
||
// String with dots | ||
obj = { a: { b: 1 } }; | ||
start = Date.now(); | ||
for (let i = 0; i < 10000000; ++i) { | ||
get(obj, 'a.b', null); | ||
} | ||
console.log('String with dots', Date.now() - start); | ||
|
||
// Multi element array | ||
obj = { a: { b: 1 } }; | ||
start = Date.now(); | ||
arr = ['a', 'b']; | ||
for (let i = 0; i < 10000000; ++i) { | ||
get(obj, arr, null); | ||
} | ||
console.log('Multi element array', Date.now() - start); | ||
const mongoose = require('../'); | ||
|
||
run().catch(err => { | ||
console.error(err); | ||
process.exit(-1); | ||
}); | ||
|
||
async function run() { | ||
const schema = new mongoose.Schema({ | ||
field1: {type: String, default: Math.random().toString(36).slice(2, 16)}, | ||
field2: {type: String, default: Math.random().toString(36).slice(2, 16)}, | ||
field3: {type: String, default: Math.random().toString(36).slice(2, 16)}, | ||
field4: {type: String, default: Math.random().toString(36).slice(2, 16)}, | ||
field5: {type: String, default: Math.random().toString(36).slice(2, 16)}, | ||
field6: {type: String, default: Math.random().toString(36).slice(2, 16)}, | ||
field7: {type: String, default: Math.random().toString(36).slice(2, 16)}, | ||
field8: {type: String, default: Math.random().toString(36).slice(2, 16)}, | ||
}, { versionKey: false }); | ||
const TestModel = mongoose.model('Test', schema); | ||
|
||
let tests = []; | ||
for (let i = 0; i < 10000; i++) { | ||
tests.push(new TestModel()); | ||
} | ||
|
||
let loopStart = Date.now(); | ||
|
||
// run loop with mongoose objects | ||
for (let k = 0; k < 100; k++) { | ||
for (let test of tests) { | ||
test.field1; | ||
test.field2; | ||
test.field3; | ||
test.field4; | ||
test.field5; | ||
test.field6; | ||
test.field7; | ||
test.field8; | ||
} | ||
} | ||
|
||
const results = { | ||
'Model loop ms': Date.now() - loopStart | ||
}; | ||
|
||
const plainTests = []; | ||
for (let test of tests) { | ||
plainTests.push(test.toObject()); | ||
} | ||
|
||
loopStart = Date.now(); | ||
|
||
// run loop with plain objects | ||
for (let k = 0; k < 100; k++) { | ||
for (let test of plainTests) { | ||
test.field1; | ||
test.field2; | ||
test.field3; | ||
test.field4; | ||
test.field5; | ||
test.field6; | ||
test.field7; | ||
test.field8; | ||
} | ||
} | ||
|
||
results['POJO loop ms'] = Date.now() - loopStart; | ||
|
||
console.log(JSON.stringify(results, null, ' ')); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# How to Check Your Mongoose Version | ||
|
||
To check what version of Mongoose you are using in Node.js, print out the [`mongoose.version` property](./api/mongoose.html#Mongoose.prototype.version) as follows. | ||
|
||
```javascript | ||
const mongoose = require('mongoose'); | ||
|
||
console.log(mongoose.version); // '7.x.x' | ||
``` | ||
|
||
We recommend printing the Mongoose version from Node.js, because that better handles cases where you have multiple versions of Mongoose installed. | ||
You can also execute the above logic from your terminal using Node.js' `-e` flag as follows. | ||
|
||
``` | ||
# Prints current Mongoose version, e.g. 7.0.3 | ||
node -e "console.log(require('mongoose').version)" | ||
``` | ||
|
||
## Using `npm list` | ||
|
||
You can also [get the installed version of the Mongoose npm package](https://masteringjs.io/tutorials/npm/version) using `npm list`. | ||
|
||
``` | ||
$ npm list mongoose | ||
test@ /path/to/test | ||
└── mongoose@7.0.3 | ||
``` | ||
|
||
`npm list` is helpful because it can identify if you have multiple versions of Mongoose installed. | ||
|
||
Other package managers also support similar functions: | ||
|
||
- [`yarn list --pattern "mongoose"`](https://classic.yarnpkg.com/lang/en/docs/cli/list/) | ||
- [`pnpm list "mongoose"`](https://pnpm.io/cli/list) |
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
Oops, something went wrong.