66 ComparisonInfo ,
77 RuntimeBenchmarkResult ,
88 isRuntimeBenchmarkResult ,
9+ BenchmarkKind ,
910} from "./benchmark_types" ;
1011import { runRuntimeBenchmark , compareRuntimeBenchmarks } from "./runtime_benchmark" ;
1112import { json , loadBenchmarksFromDirectory , readFile } from "./util" ;
@@ -37,6 +38,8 @@ function benchmark(): void {
3738 }
3839
3940 // Output comparison info
41+ oldBenchmarkResults . sort ( sortByName ) ;
42+ newBenchmarkResults . sort ( sortByName ) ;
4043 outputBenchmarkData ( oldBenchmarkResults , newBenchmarkResults ) ;
4144}
4245benchmark ( ) ;
@@ -47,23 +50,38 @@ function sortByName({ benchmarkName: a }: BenchmarkResult, { benchmarkName: b }:
4750 return 0 ;
4851}
4952
50- function compareBenchmarks ( oldResults : BenchmarkResult [ ] , newResults : BenchmarkResult [ ] ) : ComparisonInfo {
51- const oldResultsMemory = oldResults . filter ( isMemoryBenchmarkResult ) . sort ( sortByName ) ;
52- const newResultsMemory = newResults . filter ( isMemoryBenchmarkResult ) . sort ( sortByName ) ;
53+ function compareBenchmarks (
54+ oldResults : BenchmarkResult [ ] ,
55+ newResults : BenchmarkResult [ ]
56+ ) : Record < BenchmarkKind , ComparisonInfo > {
57+ const oldResultsMemory = oldResults . filter ( isMemoryBenchmarkResult ) ;
58+ const newResultsMemory = newResults . filter ( isMemoryBenchmarkResult ) ;
5359
5460 const memoryComparisonInfo = compareMemoryBenchmarks ( oldResultsMemory , newResultsMemory ) ;
5561
56- const oldResultsRuntime = oldResults . filter ( isRuntimeBenchmarkResult ) . sort ( sortByName ) ;
57- const newResultsRuntime = newResults . filter ( isRuntimeBenchmarkResult ) . sort ( sortByName ) ;
62+ const oldResultsRuntime = oldResults . filter ( isRuntimeBenchmarkResult ) ;
63+ const newResultsRuntime = newResults . filter ( isRuntimeBenchmarkResult ) ;
5864
5965 const runtimeComparisonInfo = compareRuntimeBenchmarks ( oldResultsRuntime , newResultsRuntime ) ;
6066
6167 return {
62- summary : memoryComparisonInfo . summary + "\n" + runtimeComparisonInfo . summary ,
63- text : memoryComparisonInfo . text + "\n" + runtimeComparisonInfo . text ,
68+ [ BenchmarkKind . Memory ] : memoryComparisonInfo ,
69+ [ BenchmarkKind . Runtime ] : runtimeComparisonInfo ,
6470 } ;
6571}
6672
73+ function formatComparisonMarkdownFile ( comparisonInfo : Record < BenchmarkKind , ComparisonInfo > ) : string {
74+ let result = "" ;
75+ const benchmarkKinds = [ BenchmarkKind . Memory , BenchmarkKind . Runtime ] ;
76+ for ( const kind of benchmarkKinds ) {
77+ result += comparisonInfo [ kind ] . summary + "\n" ;
78+ }
79+ for ( const kind of benchmarkKinds ) {
80+ result += comparisonInfo [ kind ] . text + "\n" ;
81+ }
82+ return result ;
83+ }
84+
6785function outputBenchmarkData ( oldResults : BenchmarkResult [ ] , newResults : BenchmarkResult [ ] ) : void {
6886 // Output benchmark results to json
6987 if ( arg [ 0 ] ) {
@@ -82,6 +100,6 @@ function outputBenchmarkData(oldResults: BenchmarkResult[], newResults: Benchmar
82100 // Compare results
83101 const comparisonInfo = compareBenchmarks ( oldResults , newResults ) ;
84102 const markdownDataFile = io . open ( arg [ 2 ] , "w+" ) [ 0 ] ! ;
85- markdownDataFile . write ( comparisonInfo . summary + comparisonInfo . text ) ;
103+ markdownDataFile . write ( formatComparisonMarkdownFile ( comparisonInfo ) ) ;
86104 }
87105}
0 commit comments