@@ -112,7 +112,7 @@ function normalizePartialValues(values: BenchmarkResult[]): BenchmarkResult[] {
112
112
normalized . push ( ...results ) ;
113
113
114
114
const missingBenchmarks = BENCHMARKS . map ( b => b . name ) . filter (
115
- n => ! results . find ( r => r . benchmark === n )
115
+ n => ! results . find ( r => r . benchmark === n ) ,
116
116
) ;
117
117
118
118
missingBenchmarks . forEach ( benchmark => {
@@ -208,7 +208,7 @@ async function graph({
208
208
. filter (
209
209
b =>
210
210
selectedBenchmarkSet . has ( b . benchmark ) &&
211
- selectedNodeJsVersionsSet . has ( b . runtimeVersion )
211
+ selectedNodeJsVersionsSet . has ( b . runtimeVersion ) ,
212
212
)
213
213
. map ( b => ( {
214
214
...b ,
@@ -228,7 +228,7 @@ async function graph({
228
228
. filter (
229
229
b =>
230
230
selectedBenchmarkSet . has ( b . benchmark ) &&
231
- selectedBunVersionsSet . has ( b . runtimeVersion )
231
+ selectedBunVersionsSet . has ( b . runtimeVersion ) ,
232
232
)
233
233
. map ( b => ( {
234
234
...b ,
@@ -239,7 +239,7 @@ async function graph({
239
239
runtimesOrder . BUN ,
240
240
BENCHMARKS_ORDER [ b . benchmark ] ,
241
241
BUN_VERSIONS . indexOf (
242
- getBunMajorAndMinorVersionNumber ( b . runtimeVersion )
242
+ getBunMajorAndMinorVersionNumber ( b . runtimeVersion ) ,
243
243
) ,
244
244
b . runtimeVersion ,
245
245
b . benchmark ,
@@ -250,7 +250,7 @@ async function graph({
250
250
. filter (
251
251
b =>
252
252
selectedBenchmarkSet . has ( b . benchmark ) &&
253
- selectedDenoVersionsSet . has ( b . runtimeVersion )
253
+ selectedDenoVersionsSet . has ( b . runtimeVersion ) ,
254
254
)
255
255
. map ( b => ( {
256
256
...b ,
@@ -298,11 +298,11 @@ async function graph({
298
298
299
299
if ( sort === 'fastest' || ! sort ) {
300
300
sortedValues = [ ...valuesNodejs , ...valuesBun , ...valuesDeno ] . sort (
301
- ( a , b ) => b . ops - a . ops
301
+ ( a , b ) => b . ops - a . ops ,
302
302
) ;
303
303
} else if ( sort === 'alphabetically' ) {
304
304
sortedValues = [ ...valuesNodejs , ...valuesBun , ...valuesDeno ] . sort (
305
- ( a , b ) => ( a . name < b . name ? - 1 : 1 )
305
+ ( a , b ) => ( a . name < b . name ? - 1 : 1 ) ,
306
306
) ;
307
307
} else if ( sort === 'popularity' ) {
308
308
sortedValues = [ ...valuesNodejs , ...valuesBun , ...valuesDeno ] . sort (
@@ -311,18 +311,65 @@ async function graph({
311
311
const bPopularity = PACKAGES_POPULARITY [ b . name ] || 0 ;
312
312
313
313
return bPopularity - aPopularity ;
314
- }
314
+ } ,
315
315
) ;
316
316
}
317
317
318
318
// remove duplicates not sure whether vega-lite can handle that
319
319
const sortedNames : string [ ] = [ ] ;
320
+ const sortedNamesWithRank : string [ ] = [ ] ;
320
321
321
322
new Set ( sortedValues . map ( b => b . name ) ) . forEach ( n => sortedNames . push ( n ) ) ;
322
323
324
+ // Calculate average ops for ranking when multiple benchmarks are selected
325
+ const rankingScores : { [ name : string ] : number } = { } ;
326
+
327
+ sortedNames . forEach ( name => {
328
+ const libraryResults = sortedValues . filter ( v => v . name === name ) ;
329
+ if ( libraryResults . length > 0 ) {
330
+ const avgOps =
331
+ libraryResults . reduce ( ( sum , result ) => sum + result . ops , 0 ) /
332
+ libraryResults . length ;
333
+ rankingScores [ name ] = avgOps ;
334
+ }
335
+ } ) ;
336
+
337
+ // Sort by ranking score and create names with rank numbers
338
+ const rankedNames = sortedNames . sort ( ( a , b ) => {
339
+ if ( sort === 'fastest' || ! sort ) {
340
+ return rankingScores [ b ] - rankingScores [ a ] ; // Descending for fastest
341
+ } else if ( sort === 'alphabetically' ) {
342
+ return a . localeCompare ( b ) ; // Alphabetical
343
+ } else if ( sort === 'popularity' ) {
344
+ const aPopularity = PACKAGES_POPULARITY [ a ] || 0 ;
345
+ const bPopularity = PACKAGES_POPULARITY [ b ] || 0 ;
346
+ return bPopularity - aPopularity ; // Descending for popularity
347
+ }
348
+ return 0 ;
349
+ } ) ;
350
+
351
+ rankedNames . forEach ( ( name , index ) => {
352
+ const rank = index + 1 ;
353
+ const rankPrefix = `#${ rank } ` ;
354
+ sortedNamesWithRank . push ( rankPrefix + name ) ;
355
+ } ) ;
356
+
357
+ // Update the values to include rank in the name for display
358
+ const valuesWithRank = [ ...valuesNodejs , ...valuesBun , ...valuesDeno ] . map (
359
+ value => {
360
+ const rankIndex = rankedNames . indexOf ( value . name ) ;
361
+ const rank = rankIndex + 1 ;
362
+ const rankPrefix = `#${ rank } ` ;
363
+ return {
364
+ ...value ,
365
+ name : rankPrefix + value . name ,
366
+ } ;
367
+ } ,
368
+ ) ;
369
+
323
370
const vegaSpec = vegaLite . compile ( {
324
371
data : {
325
- values : [ ... valuesNodejs , ... valuesBun , ... valuesDeno ] ,
372
+ values : valuesWithRank ,
326
373
} ,
327
374
height : {
328
375
step : 15 / ( nodeJsVersionCount + bunVersionCount + denoVersionCount ) ,
@@ -339,7 +386,7 @@ async function graph({
339
386
labelAlign : 'left' ,
340
387
labelFontSize : 12 ,
341
388
} ,
342
- sort : sortedNames ,
389
+ sort : sortedNamesWithRank ,
343
390
} ,
344
391
} ,
345
392
spec : {
@@ -526,7 +573,7 @@ export class App extends Component<
526
573
this . setState ( {
527
574
selectedBenchmarks : BENCHMARKS . reduce (
528
575
( acc , b ) => ( { ...acc , [ b . name ] : true } ) ,
529
- { }
576
+ { } ,
530
577
) ,
531
578
selectedNodeJsVersions : { } ,
532
579
selectedBunVersions : { } ,
@@ -543,7 +590,7 @@ export class App extends Component<
543
590
this . state . valuesNodeJs
544
591
. map ( v => v . runtimeVersion )
545
592
. filter ( v => v !== undefined )
546
- . sort ( ( a , b ) => ( a < b ? 1 : - 1 ) )
593
+ . sort ( ( a , b ) => ( a < b ? 1 : - 1 ) ) ,
547
594
) ;
548
595
const res : string [ ] = [ ] ;
549
596
@@ -557,7 +604,7 @@ export class App extends Component<
557
604
this . state . valuesBun
558
605
. map ( v => v . runtimeVersion )
559
606
. filter ( v => v !== undefined )
560
- . sort ( ( a , b ) => ( a < b ? 1 : - 1 ) )
607
+ . sort ( ( a , b ) => ( a < b ? 1 : - 1 ) ) ,
561
608
) ;
562
609
const res : string [ ] = [ ] ;
563
610
@@ -571,7 +618,7 @@ export class App extends Component<
571
618
this . state . valuesDeno
572
619
. map ( v => v . runtimeVersion )
573
620
. filter ( v => v !== undefined )
574
- . sort ( ( a , b ) => ( a < b ? 1 : - 1 ) )
621
+ . sort ( ( a , b ) => ( a < b ? 1 : - 1 ) ) ,
575
622
) ;
576
623
const res : string [ ] = [ ] ;
577
624
@@ -816,7 +863,7 @@ export class App extends Component<
816
863
817
864
< Graph
818
865
benchmarks = { BENCHMARKS . filter (
819
- b => this . state . selectedBenchmarks [ b . name ]
866
+ b => this . state . selectedBenchmarks [ b . name ] ,
820
867
) }
821
868
nodeJsVersions = { Object . entries ( this . state . selectedNodeJsVersions )
822
869
. sort ( )
0 commit comments