File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-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 bookSchema = new mongoose . Schema ( {
14+ ticker : String ,
15+ asks : [ [ Number ] ] ,
16+ bids : [ [ Number ] ] ,
17+ timestamp : String ,
18+ } ) ;
19+
20+ const Book = mongoose . model ( 'BookNestedArray' , bookSchema ) ;
21+
22+ const doc = { asks : [ ] , bids : [ ] } ;
23+ for ( let i = 0 ; i < 10000 ; ++ i ) {
24+ doc . asks . push ( [ i ] ) ;
25+ doc . bids . push ( [ i ] ) ;
26+ }
27+
28+ if ( ! process . env . MONGOOSE_BENCHMARK_SKIP_SETUP ) {
29+ await Book . deleteMany ( { } ) ;
30+ }
31+
32+ const constructStart = Date . now ( ) ;
33+ for ( let i = 0 ; i < 100 ; ++ i ) {
34+ new Book ( doc ) ;
35+ }
36+ const constructEnd = Date . now ( ) ;
37+
38+ const inst = new Book ( doc ) ;
39+ const saveStart = Date . now ( ) ;
40+ await inst . save ( ) ;
41+ const saveEnd = Date . now ( ) ;
42+
43+ const results = {
44+ 'document construction (100x) ms' : + ( constructEnd - constructStart ) . toFixed ( 2 ) ,
45+ 'save() time ms' : + ( saveEnd - saveStart ) . toFixed ( 2 )
46+ } ;
47+
48+ console . log ( JSON . stringify ( results , null , ' ' ) ) ;
49+ process . exit ( 0 ) ;
50+ }
You can’t perform that action at this time.
0 commit comments