@@ -36,14 +36,14 @@ export enum Severity {
36
36
37
37
const DEFAULT_RESULTS_KEY = "DEFAULT" ;
38
38
39
- interface IIssue {
39
+ interface Issue {
40
40
issue : number ;
41
41
severity : Severity ;
42
42
text : string ;
43
43
link : string ;
44
44
}
45
45
46
- export const knownIssues : IIssue [ ] = [
46
+ export const knownIssues : Issue [ ] = [
47
47
{
48
48
issue : 634 ,
49
49
severity : Severity . Error ,
@@ -88,7 +88,7 @@ export const knownIssues: IIssue[] = [
88
88
} ,
89
89
] ;
90
90
91
- export function findIssue ( issueNumber : number ) : IIssue | undefined {
91
+ export function findIssue ( issueNumber : number ) : Issue | undefined {
92
92
return knownIssues . find ( ( i ) => i . issue === issueNumber ) ;
93
93
}
94
94
export enum BenchmarkType {
@@ -299,38 +299,53 @@ export class ResultTableData {
299
299
public selectedCategories : Set < number > ,
300
300
public cpuDurationMode : string ,
301
301
) {
302
- this . selectedFameworks = new Set < Framework > ( ) ;
302
+ const allowedIssues = new Set ( knownIssues . map ( ( issue ) => issue . issue ) ) ;
303
+ const defaultFrameworks = [
304
+ "vanillajs-keyed" ,
305
+ "vanillajs-1-keyed" ,
306
+ "vanillajs-non-keyed" ,
307
+ "vanillajs-1-non-keyed" ,
308
+ ] ;
303
309
304
- const allowedIssues = new Set < number > ( ) ;
305
- knownIssues . forEach ( ( i ) => allowedIssues . add ( i . issue ) ) ;
306
310
console . log ( "ResultTableData" , allowedIssues , selectedCategories ) ;
307
311
308
- selectedFrameworksInDropdown . forEach ( ( f ) => {
312
+ this . selectedFameworks = new Set < Framework > ( ) ;
313
+
314
+ selectedFrameworksInDropdown . forEach ( ( framework ) => {
309
315
if (
310
- f . issues . every ( ( i ) => allowedIssues . has ( i ) ) ||
311
- f . name === "vanillajs-keyed" ||
312
- f . name === "vanillajs-1-keyed" ||
313
- f . name === "vanillajs-non-keyed" ||
314
- f . name === "vanillajs-1-non-keyed"
316
+ this . isFrameworkAllowed ( framework , allowedIssues , defaultFrameworks )
315
317
) {
316
- this . selectedFameworks . add ( f ) ;
318
+ this . selectedFameworks . add ( framework ) ;
317
319
}
318
320
} ) ;
319
- this . frameworks = this . allFrameworks . filter (
320
- ( framework ) =>
321
- framework . type === type && this . selectedFameworks . has ( framework ) ,
322
- ) ;
321
+ this . frameworks = this . filterFrameworksByType ( this . selectedFameworks , type ) ;
323
322
this . frameworksForFactors = this . allFrameworks . filter (
324
323
( framework ) =>
325
324
framework . type === type &&
326
- ( framework . issues . every ( ( i ) => allowedIssues . has ( i ) ) ||
327
- framework . name === "vanillajs-keyed" ||
328
- framework . name === "vanillajs-1-keyed" ||
329
- framework . name === "vanillajs-non-keyed" ||
330
- framework . name === "vanillajs-1-non-keyed" ) ,
325
+ this . isFrameworkAllowed ( framework , allowedIssues , defaultFrameworks ) ,
331
326
) ;
327
+
332
328
this . update ( sortKey ) ;
333
329
}
330
+ private isFrameworkAllowed (
331
+ framework : Framework ,
332
+ allowedIssues : Set < number > ,
333
+ defaultFrameworks : Array < string > ,
334
+ ) {
335
+ return (
336
+ framework . issues . every ( ( i ) => allowedIssues . has ( i ) ) ||
337
+ defaultFrameworks . includes ( framework . name )
338
+ ) ;
339
+ }
340
+ private filterFrameworksByType (
341
+ selectedFrameworks : Set < Framework > ,
342
+ type : FrameworkType ,
343
+ ) {
344
+ return this . allFrameworks . filter (
345
+ ( framework ) =>
346
+ framework . type === type && selectedFrameworks . has ( framework ) ,
347
+ ) ;
348
+ }
334
349
private update ( sortKey : string ) {
335
350
console . time ( "update" ) ;
336
351
@@ -361,9 +376,16 @@ export class ResultTableData {
361
376
362
377
return { benchmarks, results, geomMean, comparison } ;
363
378
} ;
364
- [ BenchmarkType . CPU , BenchmarkType . MEM , BenchmarkType . STARTUP ] . forEach (
365
- ( type ) => this . resultsMap . set ( type , createResult ( type ) ) ,
366
- ) ;
379
+
380
+ const benchmarkTypes = [
381
+ BenchmarkType . CPU ,
382
+ BenchmarkType . MEM ,
383
+ BenchmarkType . STARTUP ,
384
+ ] ;
385
+ for ( const type of benchmarkTypes ) {
386
+ this . resultsMap . set ( type , createResult ( type ) ) ;
387
+ }
388
+
367
389
this . sortBy ( sortKey ) ;
368
390
console . timeEnd ( "update" ) ;
369
391
}
@@ -417,43 +439,31 @@ export class ResultTableData {
417
439
sortValue : sortValue ,
418
440
} ;
419
441
} ) ;
420
- zipped . sort ( ( a , b ) => {
421
- if ( a . sortValue ! < b . sortValue ! ) return - 1 ;
422
- else if ( a . sortValue === b . sortValue ) return 0 ;
423
- return 1 ;
424
- } ) ;
425
- const remappedIdx = zipped . map ( ( z ) => z . origIndex ) ;
442
+
443
+ const remappedIdx = zipped
444
+ . sort ( ( a , b ) => Number ( a . sortValue ) - Number ( b . sortValue ) )
445
+ . map ( ( z ) => z . origIndex ) ;
446
+
426
447
this . frameworks = this . remap ( remappedIdx , this . frameworks ) ;
427
- [ BenchmarkType . CPU , BenchmarkType . MEM , BenchmarkType . STARTUP ] . forEach (
428
- ( type ) => {
429
- this . getResult ( type ) . results = this . getResult ( type ) . results . map ( ( row ) =>
430
- this . remap ( remappedIdx , row ) ,
431
- ) ;
432
- } ,
433
- ) ;
434
- [ BenchmarkType . CPU , BenchmarkType . MEM , BenchmarkType . STARTUP ] . forEach (
435
- ( type ) => {
436
- this . getResult ( type ) . geomMean = this . remap (
437
- remappedIdx ,
438
- this . getResult ( type ) . geomMean ,
439
- ) ;
440
- } ,
441
- ) ;
442
- [ BenchmarkType . CPU , BenchmarkType . MEM , BenchmarkType . STARTUP ] . forEach (
443
- ( type ) => {
444
- this . getResult ( type ) . comparison = this . remap (
445
- remappedIdx ,
446
- this . getResult ( type ) . comparison ,
447
- ) ;
448
- } ,
449
- ) ;
448
+
449
+ const benchmarkTypes = [
450
+ BenchmarkType . CPU ,
451
+ BenchmarkType . MEM ,
452
+ BenchmarkType . STARTUP ,
453
+ ] ;
454
+
455
+ for ( const type of benchmarkTypes ) {
456
+ const result = this . getResult ( type ) ;
457
+
458
+ result . results = result . results . map ( ( row ) =>
459
+ this . remap ( remappedIdx , row ) ,
460
+ ) ;
461
+ result . geomMean = this . remap ( remappedIdx , result . geomMean ) ;
462
+ result . comparison = this . remap ( remappedIdx , result . comparison ) ;
463
+ }
450
464
}
451
465
remap < T > ( remappedIdx : Array < number > , array : Array < T > ) : Array < T > {
452
- const copy = new Array < T > ( array . length ) ;
453
- remappedIdx . forEach ( ( idx , i ) => {
454
- copy [ i ] = array [ idx ] ;
455
- } ) ;
456
- return copy ;
466
+ return remappedIdx . map ( ( idx ) => array [ idx ] ) ;
457
467
}
458
468
459
469
computeGeometricMean (
@@ -462,13 +472,13 @@ export class ResultTableData {
462
472
resultsCPUForFramework : Array < TableResultValueEntry | null > ,
463
473
) : TableResultGeommeanEntry {
464
474
let count = 0.0 ;
465
- const gMean = resultsCPUForFramework . reduce ( ( gMean , r ) => {
466
- if ( r !== null ) {
467
- count ++ ;
468
- gMean *= r . factor as number ;
469
- }
470
- return gMean ;
471
- } , 1.0 ) ;
475
+ let gMean = 1.0 ;
476
+ for ( const r of resultsCPUForFramework ) {
477
+ if ( r === null ) continue ;
478
+ gMean *= r . factor ;
479
+ count ++ ;
480
+ }
481
+
472
482
const value = Math . pow ( gMean , 1 / count ) ;
473
483
return this . compareWith
474
484
? new TableResultGeommeanEntry (
@@ -488,36 +498,10 @@ export class ResultTableData {
488
498
}
489
499
computeComparison (
490
500
framework : Framework ,
491
- benchmarksCPU : Array < Benchmark > ,
501
+ benchmarksCPU : Array < Benchmark > , // Remove cause unused
492
502
resultsCPUForFramework : Array < TableResultValueEntry | null > ,
493
503
) : TableResultComparisonEntry {
494
- if ( this . compareWith ) {
495
- let statisticResult : StatisticResult | undefined = undefined ;
496
- resultsCPUForFramework . forEach ( ( r ) => {
497
- if ( r ?. statisticResult !== StatisticResult . Undecided ) {
498
- if ( statisticResult === undefined ) {
499
- statisticResult = r ?. statisticResult ;
500
- } else {
501
- if ( statisticResult !== r ?. statisticResult )
502
- statisticResult = StatisticResult . Undecided ;
503
- }
504
- }
505
- } ) ;
506
- let label = "" ;
507
- statisticResult = statisticResult ! ?? StatisticResult . Undecided ;
508
- if ( statisticResult === StatisticResult . Faster ) {
509
- label = "faster!" ;
510
- } else if ( statisticResult === StatisticResult . Slower ) {
511
- label = "slower!" ;
512
- }
513
- return new TableResultComparisonEntry (
514
- framework . name ,
515
- framework ,
516
- label ,
517
- colorsForStatisticResult ( statisticResult ) [ 0 ] ,
518
- colorsForStatisticResult ( statisticResult ) [ 1 ] ,
519
- ) ;
520
- } else {
504
+ if ( ! this . compareWith ) {
521
505
return new TableResultComparisonEntry (
522
506
framework . name ,
523
507
framework ,
@@ -526,6 +510,33 @@ export class ResultTableData {
526
510
"#000" ,
527
511
) ;
528
512
}
513
+
514
+ let statisticResult : StatisticResult | undefined = undefined ;
515
+
516
+ for ( const r of resultsCPUForFramework ) {
517
+ if ( r ?. statisticResult !== StatisticResult . Undecided ) {
518
+ if ( ! statisticResult ) {
519
+ statisticResult = r ?. statisticResult ;
520
+ } else if ( statisticResult !== r ?. statisticResult ) {
521
+ statisticResult = StatisticResult . Undecided ;
522
+ }
523
+ }
524
+ }
525
+
526
+ let label = "" ;
527
+ statisticResult ??= StatisticResult . Undecided ;
528
+ if ( statisticResult === StatisticResult . Faster ) {
529
+ label = "faster!" ;
530
+ } else if ( statisticResult === StatisticResult . Slower ) {
531
+ label = "slower!" ;
532
+ }
533
+ return new TableResultComparisonEntry (
534
+ framework . name ,
535
+ framework ,
536
+ label ,
537
+ colorsForStatisticResult ( statisticResult ) [ 0 ] ,
538
+ colorsForStatisticResult ( statisticResult ) [ 1 ] ,
539
+ ) ;
529
540
}
530
541
531
542
computeFactors ( benchmark : Benchmark ) : Array < TableResultValueEntry | null > {
@@ -586,47 +597,49 @@ export class ResultTableData {
586
597
"#000" ,
587
598
StatisticResult . Undecided ,
588
599
) ;
589
- } else {
590
- const compareWithResults = this . results ( benchmark , this . compareWith ) ! ;
591
- const compareWithResultsValues = compareWithResults . results [ resultsKey ] ;
592
- // let meanStr = 'x'; //mean.toLocaleString('en-US', {minimumFractionDigits: 1, maximumFractionDigits: 1, useGrouping: true});
593
-
594
- // X1,..,Xn: this Framework, Y1, ..., Ym: selected Framework
595
- // https://de.wikipedia.org/wiki/Zweistichproben-t-Test
596
- let statisticalResult = undefined ;
597
- let statisticalCol = undefined ;
598
- const compareWithMean = compareWithResultsValues . mean ;
599
- const stdDev = compareWithResultsValues . standardDeviation || 0 ;
600
- const compareWithResultsStdDev =
601
- compareWithResultsValues . standardDeviation || 0 ;
602
-
603
- const x1 = resultValues . mean ;
604
- const x2 = compareWithMean ;
605
- const s1_2 = stdDev * stdDev ;
606
- const s2_2 = compareWithResultsStdDev * compareWithResultsStdDev ;
607
- const n1 = 10 ;
608
- const n2 = 10 ;
609
- const ny =
610
- Math . pow ( s1_2 / n1 + s2_2 / n2 , 2 ) /
611
- ( ( s1_2 * s1_2 ) / ( n1 * n1 * ( n1 - 1 ) ) +
612
- ( s2_2 * s2_2 ) / ( n2 * n2 * ( n2 - 1 ) ) ) ;
613
- const t = ( x1 - x2 ) / Math . sqrt ( s1_2 / n1 + s2_2 / n2 ) ;
614
- const p = ( 1.0 - jStat . studentt . cdf ( Math . abs ( t ) , ny ) ) * 2 ;
615
- statisticalCol = statisticComputeColor ( t , p ) ;
616
- statisticalResult = ( p * 100 ) . toFixed ( 3 ) + "%" ;
617
- return new TableResultValueEntry (
618
- f . name ,
619
- value ,
620
- formattedValue ,
621
- conficenceIntervalStr ,
622
- factor ,
623
- factor . toFixed ( 2 ) ,
624
- statisticalCol [ 0 ] ,
625
- statisticalCol [ 1 ] ,
626
- statisticalCol [ 2 ] ,
627
- statisticalResult ,
628
- ) ;
629
600
}
601
+
602
+ const compareWithResults = this . results ( benchmark , this . compareWith ) ! ;
603
+ const compareWithResultsValues = compareWithResults . results [ resultsKey ] ;
604
+ // let meanStr = 'x'; //mean.toLocaleString('en-US', {minimumFractionDigits: 1, maximumFractionDigits: 1, useGrouping: true});
605
+
606
+ // X1,..,Xn: this Framework, Y1, ..., Ym: selected Framework
607
+ // https://de.wikipedia.org/wiki/Zweistichproben-t-Test
608
+ let statisticalResult = undefined ;
609
+ let statisticalCol = undefined ;
610
+ const compareWithMean = compareWithResultsValues . mean ;
611
+ const stdDev = compareWithResultsValues . standardDeviation || 0 ;
612
+ const compareWithResultsStdDev =
613
+ compareWithResultsValues . standardDeviation || 0 ;
614
+
615
+ const x1 = resultValues . mean ;
616
+ const x2 = compareWithMean ;
617
+ const s1_2 = stdDev * stdDev ;
618
+ const s2_2 = compareWithResultsStdDev * compareWithResultsStdDev ;
619
+ const n1 = 10 ;
620
+ const n2 = 10 ;
621
+ const ny =
622
+ Math . pow ( s1_2 / n1 + s2_2 / n2 , 2 ) /
623
+ ( ( s1_2 * s1_2 ) / ( n1 * n1 * ( n1 - 1 ) ) +
624
+ ( s2_2 * s2_2 ) / ( n2 * n2 * ( n2 - 1 ) ) ) ;
625
+ const t = ( x1 - x2 ) / Math . sqrt ( s1_2 / n1 + s2_2 / n2 ) ;
626
+ const p = ( 1.0 - jStat . studentt . cdf ( Math . abs ( t ) , ny ) ) * 2 ;
627
+
628
+ statisticalCol = statisticComputeColor ( t , p ) ;
629
+ statisticalResult = ( p * 100 ) . toFixed ( 3 ) + "%" ;
630
+
631
+ return new TableResultValueEntry (
632
+ f . name ,
633
+ value ,
634
+ formattedValue ,
635
+ conficenceIntervalStr ,
636
+ factor ,
637
+ factor . toFixed ( 2 ) ,
638
+ statisticalCol [ 0 ] ,
639
+ statisticalCol [ 1 ] ,
640
+ statisticalCol [ 2 ] ,
641
+ statisticalResult ,
642
+ ) ;
630
643
} ) ;
631
644
}
632
645
}
0 commit comments