deno.land / x / mongoose@6.7.5 / benchmarks / benchjs / insert.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
'use strict';const mongoose = require('../../lib');const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();
const Schema = mongoose.Schema;const mongoClient = require('mongodb').MongoClient;const utils = require('../../lib/utils.js');const ObjectId = Schema.Types.ObjectId;
// 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 inserting data */
mongoose.connect('mongodb://localhost/mongoose-bench', function (err) { if (err) { throw err; } mongoClient.connect( 'mongodb://localhost/mongoose-bench', function (err, client) { if (err) { throw err; }
const db = client.db('mongoose-bench');
const Comments = new Schema(); Comments.add({ title: String, date: Date, body: String, comments: [Comments], });
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: [Comments], 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: [], }; const commentData = { title: 'test comment', date: new Date(), body: 'this be some crazzzyyyyy text that would go in a comment', comments: [ { title: 'second level', date: new Date(), body: 'texttt', }, ], }; for (let i = 0; i < 5; i++) { blogData.comments.push(commentData); } const data = { name: 'name', age: 0, likes: ['dogs', 'cats', 'pizza'], address: ' Nowhere-ville USA', };
const UserSchema = new Schema({ name: String, age: Number, likes: [String], address: String, });
const User = mongoose.model('User', UserSchema); BlogPost = mongoose.model('BlogPost', BlogPost); const user = db.collection('user'); const blogpost = db.collection('blogpost');
function closeDB() { mongoose.connection.db.dropDatabase(function () { mongoose.disconnect(); process.exit(); }); }
suite .add('Insert - Mongoose - Basic', { defer: true, fn: function (deferred) { const nData = utils.clone(data); User.create(nData, function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .add('Insert - Driver - Basic', { defer: true, fn: function (deferred) { const nData = utils.clone(data); user.insertOne(nData, function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .add('Insert - Mongoose - Embedded Docs', { defer: true, fn: function (deferred) { const bp = utils.clone(blogData); BlogPost.create(bp, function (err) { if (err) { throw err; } deferred.resolve(); }); }, }) .add('Insert - Driver - Embedded Docs', { defer: true, fn: function (deferred) { const bp = utils.clone(blogData); blogpost.insertOne(bp, 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 }); } }) .run({ async: true }); } );});
mongoose

Version Info

Tagged at
a year ago