File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const mongoose = require ( '../' ) ;
4+
5+ run ( ) . catch ( err => {
6+ console . error ( err ) ;
7+ process . exit ( - 1 ) ;
8+ } ) ;
9+
10+ async function run ( ) {
11+ await mongoose . connect ( 'mongodb://127.0.0.1:27017/mongoose_benchmark' ) ;
12+
13+ const levels = 12 ;
14+
15+ let schema = new mongoose . Schema ( { test : { type : String , required : true } } ) ;
16+ let doc = { test : 'gh-14897' } ;
17+ for ( let i = 0 ; i < levels ; ++ i ) {
18+ schema = new mongoose . Schema ( { level : Number , subdocs : [ schema ] } ) ;
19+ doc = { level : ( levels - i ) , subdocs : [ { ...doc } , { ...doc } ] } ;
20+ }
21+ const Test = mongoose . model ( 'Test' , schema ) ;
22+
23+ if ( ! process . env . MONGOOSE_BENCHMARK_SKIP_SETUP ) {
24+ await Test . deleteMany ( { } ) ;
25+ }
26+
27+ const insertStart = Date . now ( ) ;
28+ await Test . create ( doc ) ;
29+ const insertEnd = Date . now ( ) ;
30+
31+ const results = {
32+ 'create() time ms' : + ( insertEnd - insertStart ) . toFixed ( 2 )
33+ } ;
34+
35+ console . log ( JSON . stringify ( results , null , ' ' ) ) ;
36+ process . exit ( 0 ) ;
37+ }
You can’t perform that action at this time.
0 commit comments