forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnestedArrayLarge.js
More file actions
50 lines (39 loc) · 1.17 KB
/
nestedArrayLarge.js
File metadata and controls
50 lines (39 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'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 bookSchema = new mongoose.Schema({
ticker: String,
asks: [[Number]],
bids: [[Number]],
timestamp: String,
});
const Book = mongoose.model('BookNestedArray', bookSchema);
const doc = { asks: [], bids: [] };
for (let i = 0; i < 10000; ++i) {
doc.asks.push([i]);
doc.bids.push([i]);
}
if (!process.env.MONGOOSE_BENCHMARK_SKIP_SETUP) {
await Book.deleteMany({});
}
const constructStart = Date.now();
for (let i = 0; i < 100; ++i) {
new Book(doc);
}
const constructEnd = Date.now();
const inst = new Book(doc);
const saveStart = Date.now();
await inst.save();
const saveEnd = Date.now();
const results = {
'document construction (100x) ms': +(constructEnd - constructStart).toFixed(2),
'save() time ms': +(saveEnd - saveStart).toFixed(2)
};
console.log(JSON.stringify(results, null, ' '));
process.exit(0);
}