1
1
/// run `make perf-tester` after updating this or util.js
2
2
3
- import fs from 'fs' ;
4
- import { exec } from '@actions/exec' ;
3
+ const fs = require ( 'fs' ) ;
4
+ const { exec } = require ( '@actions/exec' ) ;
5
5
6
- export const getInput = key => ( {
6
+ const getInput = key => ( {
7
7
'build-script' : 'make bootstrap benchmark_setup' ,
8
8
benchmark : 'make -s run_benchmark' ,
9
9
'minimum-change-threshold' : 5 ,
10
10
'use-check' : 'no' ,
11
11
'repo-token' : process . env . GITHUB_TOKEN
12
12
} ) [ key ]
13
+ exports . getInput = getInput
13
14
14
- export async function runBenchmark ( ) {
15
+ exports . runBenchmark = async ( ) => {
15
16
let benchmarkBuffers = [ ]
16
17
await exec ( getInput ( 'benchmark' ) , [ ] , {
17
18
listeners : {
@@ -36,7 +37,7 @@ function parse(benchmarkData) {
36
37
return benchmarks
37
38
}
38
39
39
- export function averageBenchmarks ( benchmarks ) {
40
+ exports . averageBenchmarks = ( benchmarks ) => {
40
41
const result = Object . create ( null )
41
42
for ( const key of Object . keys ( benchmarks [ 0 ] ) ) {
42
43
result [ key ] = benchmarks . reduce ( ( acc , bench ) => acc + bench [ key ] , 0 ) / benchmarks . length
@@ -49,7 +50,7 @@ export function averageBenchmarks(benchmarks) {
49
50
* @param {{[key: string]: number} } after
50
51
* @return {Diff[] }
51
52
*/
52
- export function toDiff ( before , after ) {
53
+ exports . toDiff = ( before , after ) => {
53
54
const names = [ ...new Set ( [ ...Object . keys ( before ) , ...Object . keys ( after ) ] ) ]
54
55
return names . map ( name => {
55
56
const timeBefore = before [ name ] || 0
@@ -60,49 +61,11 @@ export function toDiff(before, after) {
60
61
}
61
62
62
63
63
- /**
64
- * Check if a given file exists and can be accessed.
65
- * @param {string } filename
66
- */
67
- export async function fileExists ( filename ) {
68
- try {
69
- await fs . promises . access ( filename , fs . constants . F_OK ) ;
70
- return true ;
71
- } catch ( e ) { }
72
- return false ;
73
- }
74
-
75
- /**
76
- * Remove any matched hash patterns from a filename string.
77
- * @param {string= } regex
78
- * @returns {(((fileName: string) => string) | undefined) }
79
- */
80
- export function stripHash ( regex ) {
81
- if ( regex ) {
82
- console . log ( `Striping hash from build chunks using '${ regex } ' pattern.` ) ;
83
- return function ( fileName ) {
84
- return fileName . replace ( new RegExp ( regex ) , ( str , ...hashes ) => {
85
- hashes = hashes . slice ( 0 , - 2 ) . filter ( ( c ) => c != null ) ;
86
- if ( hashes . length ) {
87
- for ( let i = 0 ; i < hashes . length ; i ++ ) {
88
- const hash = hashes [ i ] || '' ;
89
- str = str . replace ( hash , hash . replace ( / ./ g, '*' ) ) ;
90
- }
91
- return str ;
92
- }
93
- return '' ;
94
- } ) ;
95
- } ;
96
- }
97
-
98
- return undefined ;
99
- }
100
-
101
64
/**
102
65
* @param {number } delta
103
66
* @param {number } difference
104
67
*/
105
- export function getDeltaText ( delta , difference ) {
68
+ function getDeltaText ( delta , difference ) {
106
69
let deltaText = ( delta > 0 ? '+' : '' ) + delta . toLocaleString ( 'en-US' ) + 'ms' ;
107
70
if ( delta && Math . abs ( delta ) > 1 ) {
108
71
deltaText += ` (${ Math . abs ( difference ) } %)` ;
@@ -113,7 +76,7 @@ export function getDeltaText(delta, difference) {
113
76
/**
114
77
* @param {number } difference
115
78
*/
116
- export function iconForDifference ( difference ) {
79
+ function iconForDifference ( difference ) {
117
80
let icon = '' ;
118
81
if ( difference >= 50 ) icon = '🆘' ;
119
82
else if ( difference >= 20 ) icon = '🚨' ;
@@ -174,7 +137,7 @@ function markdownTable(rows) {
174
137
* @param {boolean } [options.omitUnchanged]
175
138
* @param {number } [options.minimumChangeThreshold]
176
139
*/
177
- export function diffTable ( tests , { showTotal, collapseUnchanged, omitUnchanged, minimumChangeThreshold } ) {
140
+ exports . diffTable = ( tests , { showTotal, collapseUnchanged, omitUnchanged, minimumChangeThreshold } ) => {
178
141
let changedRows = [ ] ;
179
142
let unChangedRows = [ ] ;
180
143
@@ -225,6 +188,4 @@ export function diffTable(tests, { showTotal, collapseUnchanged, omitUnchanged,
225
188
* Convert a string "true"/"yes"/"1" argument value to a boolean
226
189
* @param {string } v
227
190
*/
228
- export function toBool ( v ) {
229
- return / ^ ( 1 | t r u e | y e s ) $ / . test ( v ) ;
230
- }
191
+ exports . toBool = v => / ^ ( 1 | t r u e | y e s ) $ / . test ( v ) ;
0 commit comments