1
1
/* eslint-disable no-console */
2
+ import assert from 'node:assert/strict' ;
2
3
import child_process from 'node:child_process' ;
3
4
import events from 'node:events' ;
4
5
import fs from 'node:fs/promises' ;
@@ -7,6 +8,9 @@ import path from 'node:path';
7
8
import util from 'node:util' ;
8
9
9
10
import {
11
+ type Metric ,
12
+ type MetricInfo ,
13
+ metrics ,
10
14
MONGODB_BSON_PATH ,
11
15
MONGODB_BSON_REVISION ,
12
16
MONGODB_BSON_VERSION ,
@@ -81,7 +85,7 @@ console.log(systemInfo());
81
85
82
86
const runnerPath = path . join ( __dirname , 'runner.mjs' ) ;
83
87
84
- const results = [ ] ;
88
+ const results : MetricInfo [ ] = [ ] ;
85
89
86
90
for ( const [ suite , benchmarks ] of Object . entries ( tests ) ) {
87
91
console . group ( snakeToCamel ( suite ) ) ;
@@ -106,4 +110,94 @@ for (const [suite, benchmarks] of Object.entries(tests)) {
106
110
console . groupEnd ( ) ;
107
111
}
108
112
109
- await fs . writeFile ( 'results.json' , JSON . stringify ( results , undefined , 2 ) , 'utf8' ) ;
113
+ function calculateCompositeBenchmarks ( results : MetricInfo [ ] ) {
114
+ const composites = {
115
+ singleBench : [ 'findOne' , 'smallDocInsertOne' , 'largeDocInsertOne' ] ,
116
+ multiBench : [
117
+ 'findManyAndEmptyCursor' ,
118
+ 'gridFsDownload' ,
119
+ 'gridFsUpload' ,
120
+ 'largeDocBulkInsert' ,
121
+ 'smallDocBulkInsert'
122
+ ] ,
123
+ // parallelBench: [
124
+ // 'ldjsonMultiFileUpload',
125
+ // 'ldjsonMultiFileExport',
126
+ // 'gridfsMultiFileUpload',
127
+ // 'gridfsMultiFileDownload'
128
+ // ],
129
+ readBench : [
130
+ 'findOne' ,
131
+ 'findManyAndEmptyCursor' ,
132
+ 'gridFsDownload'
133
+ // 'gridfsMultiFileDownload',
134
+ // 'ldjsonMultiFileExport'
135
+ ] ,
136
+ writeBench : [
137
+ 'smallDocInsertOne' ,
138
+ 'largeDocInsertOne' ,
139
+ 'smallDocBulkInsert' ,
140
+ 'largeDocBulkInsert' ,
141
+ 'gridFsUpload'
142
+ // 'ldjsonMultiFileUpload',
143
+ // 'gridfsMultiFileUpload'
144
+ ]
145
+ } ;
146
+
147
+ const aMetricInfo =
148
+ ( testName : string ) =>
149
+ ( { info : { test_name } } : MetricInfo ) =>
150
+ test_name === testName ;
151
+
152
+ const anMBsMetric = ( { name } : Metric ) => name === 'megabytes_per_second' ;
153
+
154
+ let readBenchResult ;
155
+ let writeBenchResult ;
156
+
157
+ console . group ( 'composite scores' ) ;
158
+
159
+ const compositeResults : MetricInfo [ ] = [ ] ;
160
+ for ( const [ compositeName , compositeTests ] of Object . entries ( composites ) ) {
161
+ console . group ( `${ compositeName } : ${ compositeTests . join ( ', ' ) } ` ) ;
162
+
163
+ let sum = 0 ;
164
+ for ( const testName of compositeTests ) {
165
+ const testScore = results . find ( aMetricInfo ( testName ) ) ;
166
+ assert . ok ( testScore , `${ compositeName } suite requires ${ testName } for composite score` ) ;
167
+
168
+ const metric = testScore . metrics . find ( anMBsMetric ) ;
169
+ assert . ok ( metric , `${ testName } is missing a megabytes_per_second metric` ) ;
170
+
171
+ sum += metric . value ;
172
+ }
173
+
174
+ const compositeAverage = sum / compositeTests . length ;
175
+
176
+ if ( compositeName === 'readBench' ) readBenchResult = compositeAverage ;
177
+ if ( compositeName === 'writeBench' ) writeBenchResult = compositeAverage ;
178
+
179
+ compositeResults . push ( metrics ( compositeName , compositeAverage ) ) ;
180
+
181
+ console . log ( 'avg:' , compositeAverage , 'mb/s' ) ;
182
+
183
+ console . groupEnd ( ) ;
184
+ }
185
+
186
+ assert . ok ( typeof readBenchResult === 'number' ) ;
187
+ assert . ok ( typeof writeBenchResult === 'number' ) ;
188
+
189
+ const driverBench = ( readBenchResult + writeBenchResult ) / 2 ;
190
+
191
+ console . group ( 'driverBench: readBench, writeBench' ) ;
192
+ console . log ( 'avg:' , driverBench , 'mb/s' ) ;
193
+ console . groupEnd ( ) ;
194
+
195
+ compositeResults . push ( metrics ( 'driverBench' , driverBench ) ) ;
196
+
197
+ console . groupEnd ( ) ;
198
+ return [ ...results , ...compositeResults ] ;
199
+ }
200
+
201
+ const finalResults = calculateCompositeBenchmarks ( results ) ;
202
+
203
+ await fs . writeFile ( 'results.json' , JSON . stringify ( finalResults , undefined , 2 ) , 'utf8' ) ;
0 commit comments