11/* eslint-disable no-console */
2+ import assert from 'node:assert/strict' ;
23import child_process from 'node:child_process' ;
34import events from 'node:events' ;
45import fs from 'node:fs/promises' ;
@@ -7,6 +8,9 @@ import path from 'node:path';
78import util from 'node:util' ;
89
910import {
11+ type Metric ,
12+ type MetricInfo ,
13+ metrics ,
1014 MONGODB_BSON_PATH ,
1115 MONGODB_BSON_REVISION ,
1216 MONGODB_BSON_VERSION ,
@@ -81,7 +85,7 @@ console.log(systemInfo());
8185
8286const runnerPath = path . join ( __dirname , 'runner.mjs' ) ;
8387
84- const results = [ ] ;
88+ const results : MetricInfo [ ] = [ ] ;
8589
8690for ( const [ suite , benchmarks ] of Object . entries ( tests ) ) {
8791 console . group ( snakeToCamel ( suite ) ) ;
@@ -106,4 +110,94 @@ for (const [suite, benchmarks] of Object.entries(tests)) {
106110 console . groupEnd ( ) ;
107111}
108112
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