deno.land / x / mongoose@6.7.5 / benchmarks / benchjs / casting.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
'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 casting stuff */
const Comments = new Schema();
Comments.add({ title: String, date: Date, body: String, comments: [Comments],});
const 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 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' }],};
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 blogData10 = utils.clone(blogData);const blogData100 = utils.clone(blogData);const blogData1000 = utils.clone(blogData);const blogData10000 = utils.clone(blogData);
for (let i = 0; i < 10; i++) { blogData10.comments.push(commentData);}for (let i = 0; i < 100; i++) { blogData100.comments.push(commentData);}for (let i = 0; i < 1000; i++) { blogData1000.comments.push(commentData);}for (let i = 0; i < 10000; i++) { blogData10000.comments.push(commentData);}
mongoose.model('BlogPost', BlogPost);
suite .add('Casting - Embedded Docs - 0 Docs', { fn: function () { const BlogPost = mongoose.model('BlogPost'); const bp = new BlogPost(); bp.init(blogData); }, }) .add('Casting - Embedded Docs - 10 Docs', { fn: function () { const BlogPost = mongoose.model('BlogPost'); const bp = new BlogPost(); bp.init(blogData10); }, }) .add('Casting - Embedded Docs - 100 Docs', { fn: function () { const BlogPost = mongoose.model('BlogPost'); const bp = new BlogPost(); bp.init(blogData100); }, }) .add('Casting - Embedded Docs - 1000 Docs', { fn: function () { const BlogPost = mongoose.model('BlogPost'); const bp = new BlogPost(); bp.init(blogData1000); }, }) .add('Casting - Embedded Docs - 10000 Docs', { fn: function () { const BlogPost = mongoose.model('BlogPost'); const bp = new BlogPost(); bp.init(blogData10000); }, }) .on('cycle', function (evt) { if (process.env.MONGOOSE_DEV || process.env.PULL_REQUEST) { console.log(String(evt.target)); } }) .on('complete', function () { 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