File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const mongoose = require ( '../' ) ;
4+ const Benchmark = require ( 'benchmark' ) ;
5+
6+ const { Schema } = mongoose ;
7+
8+ run ( ) . catch ( err => {
9+ console . error ( err ) ;
10+ process . exit ( 1 ) ;
11+ } ) ;
12+
13+ async function run ( ) {
14+ await mongoose . connect ( 'mongodb://127.0.0.1:27017/mongoose_benchmark' ) ;
15+
16+ const bookSchema = new Schema ( {
17+ ticker : String ,
18+ asks : [ [ Number ] ] ,
19+ bids : [ [ Number ] ] ,
20+ timestamp : String ,
21+ } ) ;
22+
23+ const Book = mongoose . model ( 'BookNestedArray' , bookSchema ) ;
24+
25+ let doc = { asks : [ ] , bids : [ ] } ;
26+ for ( let i = 0 ; i < 10000 ; ++ i ) {
27+ doc . asks . push ( [ i ] ) ;
28+ doc . bids . push ( [ i ] ) ;
29+ }
30+
31+ const suite = new Benchmark . Suite ( ) ;
32+
33+ suite
34+ . add ( 'BookNestedArray document construction' , function ( ) {
35+ new Book ( doc ) ;
36+ } )
37+ . on ( 'cycle' , function ( evt ) {
38+ if ( process . env . MONGOOSE_DEV || process . env . PULL_REQUEST ) {
39+ console . log ( String ( evt . target ) ) ;
40+ }
41+ } )
42+ . run ( ) ;
43+
44+ await mongoose . disconnect ( ) ;
45+ }
You can’t perform that action at this time.
0 commit comments