deno.land / x / mongoose@6.7.5 / benchmarks / benchjs / population.js

نووسراو ببینە
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
'use strict';const mongoose = require('../../lib');const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();
const Schema = mongoose.Schema;const ObjectId = Schema.Types.ObjectId;const utils = require('../../lib/utils.js');
// to make things work in the way the are normally described online.../* *global.Schema = Schema; *global.mongoose = mongoose; */
/** * These are all the benchmark tests for population ops */
mongoose.connect('mongodb://localhost/mongoose-bench', function (err) { if (err) { throw err; }
const commentSchema = new Schema(); commentSchema.add({ title: String, date: Date, body: String, }); const dummy1Schema = new Schema({ title: String, isThisTest: Boolean, }); const dummy2Schema = new Schema({ title: String, isThisTest: Boolean, }); const dummy3Schema = new Schema({ title: String, isThisTest: Boolean, }); const dummy4Schema = new Schema({ title: String, isThisTest: Boolean, }); const dummy5Schema = new Schema({ title: String, isThisTest: Boolean, }); const dummy6Schema = new Schema({ title: String, isThisTest: Boolean, }); const dummy7Schema = new Schema({ title: String, isThisTest: Boolean, }); const dummy8Schema = new Schema({ title: String, isThisTest: Boolean, }); const dummy9Schema = new Schema({ title: String, isThisTest: Boolean, });
let BlogPost = new Schema({ title: String, author: String, slug: String, date: Date, meta: { date: Date, visitors: Number, }, published: Boolean, mixed: {}, numbers: [Number], tags: [String], owners: [ObjectId], comments: [{ type: ObjectId, ref: 'Comment' }], dummy1: [{ type: ObjectId, ref: 'Dummy1' }], dummy2: [{ type: ObjectId, ref: 'Dummy2' }], dummy3: [{ type: ObjectId, ref: 'Dummy3' }], dummy4: [{ type: ObjectId, ref: 'Dummy4' }], dummy5: [{ type: ObjectId, ref: 'Dummy5' }], dummy6: [{ type: ObjectId, ref: 'Dummy6' }], dummy7: [{ type: ObjectId, ref: 'Dummy7' }], dummy8: [{ type: ObjectId, ref: 'Dummy8' }], dummy9: [{ type: ObjectId, ref: 'Dummy9' }], def: { type: String, default: 'kandinsky' }, });
const blogData = { title: 'dummy post', author: 'somebody', slug: 'test.post', date: new Date(), meta: { date: new Date(), visitors: 9001 }, published: true, mixed: { thisIsRandom: true }, numbers: [1, 2, 7, 10, 23432], tags: ['test', 'BENCH', 'things', 'more things'], def: 'THANGS!!!', comments: [], dummy1: [], dummy2: [], dummy3: [], dummy4: [], dummy5: [], dummy6: [], dummy7: [], dummy8: [], dummy9: [], }; const commentData = { title: 'test comment', date: new Date(), body: 'this be some crazzzyyyyy text that would go in a comment', }; const dummyData = { title: 'dummy data~', isThisTest: true, }; const Comments = mongoose.model('Comment', commentSchema); BlogPost = mongoose.model('BlogPost', BlogPost); const Dummy1 = mongoose.model('Dummy1', dummy1Schema); const Dummy2 = mongoose.model('Dummy2', dummy2Schema); const Dummy3 = mongoose.model('Dummy3', dummy3Schema); const Dummy4 = mongoose.model('Dummy4', dummy4Schema); const Dummy5 = mongoose.model('Dummy5', dummy5Schema); const Dummy6 = mongoose.model('Dummy6', dummy6Schema); const Dummy7 = mongoose.model('Dummy7', dummy7Schema); const Dummy8 = mongoose.model('Dummy8', dummy8Schema); const Dummy9 = mongoose.model('Dummy9', dummy9Schema); const cIds = []; const dIds = []; for (let i = 0; i < 9; i++) { dIds.push([]); }
let cn = 5000; for (let i = 0; i < 500; i++) { Comments.create(commentData, function (err, com) { cIds.push(com.id); --cn || cont(); }); Dummy1.create(dummyData, function (err, d) { if (err) { throw err; } dIds[0].push(d.id); --cn || cont(); }); Dummy2.create(dummyData, function (err, d) { if (err) { throw err; } dIds[1].push(d.id); --cn || cont(); }); Dummy3.create(dummyData, function (err, d) { if (err) { throw err; } dIds[2].push(d.id); --cn || cont(); }); Dummy4.create(dummyData, function (err, d) { if (err) { throw err; } dIds[3].push(d.id); --cn || cont(); }); Dummy5.create(dummyData, function (err, d) { if (err) { throw err; } dIds[4].push(d.id); --cn || cont(); }); Dummy6.create(dummyData, function (err, d) { if (err) { throw err; } dIds[5].push(d.id); --cn || cont(); }); Dummy7.create(dummyData, function (err, d) { if (err) { throw err; } dIds[6].push(d.id); --cn || cont(); }); Dummy8.create(dummyData, function (err, d) { if (err) { throw err; } dIds[7].push(d.id); --cn || cont(); }); Dummy9.create(dummyData, function (err, d) { if (err) { throw err; } dIds[8].push(d.id); --cn || cont(); }); }
const blog = [];
function cont() { blog[0] = utils.clone(blogData); blog[1] = utils.clone(blogData); blog[2] = utils.clone(blogData); blog[3] = utils.clone(blogData); blogData.comments.push(getNextcId()); blog[4] = blogData;
blog[5] = utils.clone(blogData); blog[6] = utils.clone(blogData);
for (let i = 0; i < 10; i++) { blog[0].comments.push(getNextcId()); } for (let i = 0; i < 100; i++) { blog[1].comments.push(getNextcId()); } for (let i = 0; i < 1000; i++) { blog[2].comments.push(getNextcId()); } for (let i = 0; i < 10000; i++) { blog[3].comments.push(getNextcId()); } for (let i = 0; i < 100; i++) { blog[5].comments.push(getNextcId()); blog[6].comments.push(getNextcId());
blog[5].dummy1.push(getNextdId(0)); blog[5].dummy2.push(getNextdId(1)); blog[5].dummy3.push(getNextdId(2)); blog[5].dummy4.push(getNextdId(3));
blog[6].dummy1.push(getNextdId(0)); blog[6].dummy2.push(getNextdId(1)); blog[6].dummy3.push(getNextdId(2)); blog[6].dummy4.push(getNextdId(3)); blog[6].dummy5.push(getNextdId(4)); blog[6].dummy1.push(getNextdId(5)); blog[6].dummy2.push(getNextdId(6)); blog[6].dummy3.push(getNextdId(7)); blog[6].dummy4.push(getNextdId(8)); }
let count = 7;
function iter(c) { BlogPost.create(blog[c], function (err, bl) { if (err) { throw err; } blog[c] = bl; --count || next(); }); }
// insert all of the data here for (let i = 0; i < blog.length; i++) { // use some closure magic to make sure we retain the index iter(i); } }
let ci = 0; const di = []; for (let i = 0; i < 9; i++) { di.push(0); }
function getNextcId() { ci = ++ci % cIds.length; return cIds[ci]; }
function getNextdId(i) { di[i] = ++di[i] % dIds[i].length; return dIds[i][di[i]]; }
function closeDB() { // just a bit simpler... mongoose.connection.db.dropDatabase(function () { mongoose.disconnect(); process.exit(); }); }
suite .add('Populate - 1 value', { defer: true, fn: function (deferred) { blog[4].populate('comments', function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .add('Populate - 10 values', { defer: true, fn: function (deferred) { blog[0].populate('comments', function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .add('Populate - 100 values', { defer: true, fn: function (deferred) { blog[1].populate('comments', function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .add('Populate - 1000 values', { defer: true, fn: function (deferred) { blog[2].populate('comments', function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .add('Populate - 10000 values', { defer: true, fn: function (deferred) { blog[3].populate('comments', function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .add('Populate - 5 properties', { defer: true, fn: function (deferred) { blog[5].populate( 'comments dummy1 dummy2 dummy3 dummy4', function (err) { if (err) { throw err; } deferred.resolve(); } ); }, }) .add('Populate - 10 properties', { defer: true, fn: function (deferred) { blog[6].populate( 'comments dummy1 dummy2 dummy3 dummy4 dummy5 dummy6 dummy7 dummy8 dummy9', function (err) { if (err) { throw err; } deferred.resolve(); } ); }, })
.on('cycle', function (evt) { if (process.env.MONGOOSE_DEV || process.env.PULL_REQUEST) { console.log(String(evt.target)); } }) .on('complete', function () { closeDB(); if (!process.env.MONGOOSE_DEV && !process.env.PULL_REQUEST) { const outObj = {}; this.forEach(function (item) { const out = {}; out.stats = item.stats; delete out.stats.sample; out.ops = item.hz; outObj[item.name.replace(/\s/g, '')] = out; }); console.dir(outObj, { depth: null, colors: true }); } }); function next() { suite.run({ async: true }); }});
mongoose

Version Info

Tagged at
a year ago