11import { BenchmarkKind , MemoryBenchmarkResult } from "./benchmark_types" ;
22import { round , json } from "./util" ;
33
4-
54export function runMemoryBenchmark ( benchmarkFunction : Function ) : MemoryBenchmarkResult {
6- let result : MemoryBenchmarkResult = { kind : BenchmarkKind . Memory , benchmarkName : "NO_NAME" , preExecMemoryUsage : 0 , postExecMemoryUsage : 0 , memoryUsedForExec : 0 , memoryAfterGC : 0 } ;
5+ let result : MemoryBenchmarkResult = {
6+ kind : BenchmarkKind . Memory ,
7+ benchmarkName : "NO_NAME" ,
8+ preExecMemoryUsage : 0 ,
9+ postExecMemoryUsage : 0 ,
10+ memoryUsedForExec : 0 ,
11+ memoryAfterGC : 0 ,
12+ } ;
713
8- collectgarbage ( ' stop' )
14+ collectgarbage ( " stop" ) ;
915 result . preExecMemoryUsage = collectgarbage ( "count" ) ;
1016
1117 benchmarkFunction ( ) ;
1218
1319 result . postExecMemoryUsage = collectgarbage ( "count" ) ;
1420 result . memoryUsedForExec = result . postExecMemoryUsage - result . preExecMemoryUsage ;
1521
16- collectgarbage ( "restart" )
17- collectgarbage ( "collect" )
22+ collectgarbage ( "restart" ) ;
23+ collectgarbage ( "collect" ) ;
1824
1925 result . memoryAfterGC = collectgarbage ( "count" ) ;
2026
@@ -23,25 +29,36 @@ export function runMemoryBenchmark(benchmarkFunction: Function): MemoryBenchmark
2329 return result ;
2430}
2531
26- export function compareMemoryBenchmarks ( oldResults : MemoryBenchmarkResult [ ] , updatedResults : MemoryBenchmarkResult [ ] ) : [ string , string ] {
32+ export function compareMemoryBenchmarks (
33+ oldResults : MemoryBenchmarkResult [ ] ,
34+ updatedResults : MemoryBenchmarkResult [ ]
35+ ) : [ string , string ] {
2736 let comparisonTable = "| name | master (kb) | commit (kb) | change (kb) | change (%) |\n| - | - | - | - | - |\n" ;
2837
2938 // we group by the new results in case benchmarks have been added
3039 updatedResults . forEach ( newResult => {
3140 const masterResult = oldResults . find ( r => r . benchmarkName == newResult . benchmarkName ) ;
3241 if ( masterResult ) {
33- const percentageChange = newResult . memoryUsedForExec / masterResult . memoryUsedForExec * 100 - 100 ;
34- comparisonTable += `| ${ newResult . benchmarkName } | ${ round ( masterResult . memoryUsedForExec , 3 ) } | ${ round ( newResult . memoryUsedForExec , 3 ) } | ${ round ( newResult . memoryUsedForExec - masterResult . memoryUsedForExec , 3 ) } | ${ round ( percentageChange , 2 ) } |\n` ;
42+ const percentageChange = ( newResult . memoryUsedForExec / masterResult . memoryUsedForExec ) * 100 - 100 ;
43+ comparisonTable += `| ${ newResult . benchmarkName } | ${ round ( masterResult . memoryUsedForExec , 3 ) } | ${ round (
44+ newResult . memoryUsedForExec ,
45+ 3
46+ ) } | ${ round ( newResult . memoryUsedForExec - masterResult . memoryUsedForExec , 3 ) } | ${ round (
47+ percentageChange ,
48+ 2
49+ ) } |\n`;
3550 } else {
3651 // No master found => new benchmark
37- comparisonTable += `| ${ newResult . benchmarkName } (new) | / | ${ round ( newResult . memoryUsedForExec , 3 ) } | / | / |\n` ;
52+ comparisonTable += `| ${ newResult . benchmarkName } (new) | / | ${ round (
53+ newResult . memoryUsedForExec ,
54+ 3
55+ ) } | / | / |\n`;
3856 }
3957 } ) ;
4058
4159 const markdownSummary = `**Memory:**\n${ comparisonTable } ` ;
4260
43- const markdownText =
44- `**master:**\n${ json . encode ( oldResults ) } \n**commit:**\n${ json . encode ( updatedResults ) } ` ;
61+ const markdownText = `**master:**\n${ json . encode ( oldResults ) } \n**commit:**\n${ json . encode ( updatedResults ) } ` ;
4562
46- return [ markdownSummary , markdownText ]
47- }
63+ return [ markdownSummary , markdownText ] ;
64+ }
0 commit comments