@@ -81,6 +81,51 @@ export const clearCaches = async (directory) => {
81
81
) ;
82
82
} ;
83
83
84
+ const T_TABLE = [
85
+ 12.71 ,
86
+ 4.303 ,
87
+ 3.182 ,
88
+ 2.776 ,
89
+ 2.571 ,
90
+ 2.447 ,
91
+ 2.365 ,
92
+ 2.306 ,
93
+ 2.262 ,
94
+ 2.228 ,
95
+ 2.201 ,
96
+ 2.179 ,
97
+ 2.16 ,
98
+ 2.145 ,
99
+ 2.131 ,
100
+ 2.12 ,
101
+ 2.11 ,
102
+ 2.101 ,
103
+ 2.093 ,
104
+ 2.086 ,
105
+ 2.08 ,
106
+ 2.074 ,
107
+ 2.069 ,
108
+ 2.064 ,
109
+ 2.06 ,
110
+ 2.056 ,
111
+ 2.052 ,
112
+ 2.048 ,
113
+ 2.045 ,
114
+ 2.042 ,
115
+ ] ;
116
+
117
+ const tDist95Two = ( n ) => {
118
+ if ( n <= 1 ) return 12.71 ;
119
+ if ( n <= 30 ) return T_TABLE [ n - 1 ] ;
120
+ if ( n <= 40 ) return 2.021 ;
121
+ if ( n <= 50 ) return 2.009 ;
122
+ if ( n <= 60 ) return 2.0 ;
123
+ if ( n <= 80 ) return 1.99 ;
124
+ if ( n <= 100 ) return 1.984 ;
125
+ if ( n <= 120 ) return 1.98 ;
126
+ return 1.96 ;
127
+ } ;
128
+
84
129
export const calcStatistics = ( results ) => {
85
130
const stats = { } ;
86
131
for ( const key of Object . keys ( results [ 0 ] ) ) {
@@ -93,6 +138,8 @@ export const calcStatistics = (results) => {
93
138
const variance =
94
139
values . reduce ( ( sum , v ) => sum + ( mean - v ) ** 2 , 0 ) / values . length ;
95
140
const stdDev = Math . sqrt ( variance ) ;
141
+ const confidence =
142
+ ( tDist95Two ( values . length - 1 ) * stdDev ) / Math . sqrt ( values . length ) ;
96
143
stats [ key ] = {
97
144
min : Math . min ( ...values ) ,
98
145
max : Math . max ( ...values ) ,
@@ -103,8 +150,9 @@ export const calcStatistics = (results) => {
103
150
: values [ ( values . length - 1 ) / 2 ] ,
104
151
variance,
105
152
stdDev,
106
- low : mean - stdDev ,
107
- high : mean + stdDev ,
153
+ confidence : confidence * 2 ,
154
+ low : mean - confidence ,
155
+ high : mean + confidence ,
108
156
count : values . length ,
109
157
} ;
110
158
}
@@ -123,9 +171,6 @@ export const compareStatistics = (
123
171
const currentValue = current [ key ] ;
124
172
if ( baseValue === undefined || currentValue === undefined ) continue ;
125
173
if ( "mean" in baseValue ) {
126
- const getDiff = ( b , c ) => {
127
- return c / b ;
128
- } ;
129
174
diff [ key ] = {
130
175
relevance : currentValue . mean / total ,
131
176
} ;
@@ -136,20 +181,34 @@ export const compareStatistics = (
136
181
diff [ key ] . highLow = currentValue . low / baseValue . high ;
137
182
diff [ key ] . baseStdDev = baseValue . stdDev / baseValue . mean ;
138
183
diff [ key ] . currentStdDev = currentValue . stdDev / currentValue . mean ;
184
+ diff [ key ] . baseConfidence = baseValue . confidence / baseValue . mean ;
185
+ diff [ key ] . currentConfidence = currentValue . confidence / currentValue . mean ;
139
186
} else {
140
187
diff [ key ] = compareStatistics ( baseValue , currentValue , total ) ;
141
188
}
142
189
}
143
190
return diff ;
144
191
} ;
145
192
146
- export const formatDiffTable = ( diff , colors ) => {
147
- const entries = Object . keys ( diff ) . map ( ( key ) => ( { name : key , ...diff [ key ] } ) ) ;
193
+ export const formatDiffTable = (
194
+ diff ,
195
+ { colors, verbose, limit, threshold }
196
+ ) => {
197
+ let entries = Object . keys ( diff ) . map ( ( key ) => ( { name : key , ...diff [ key ] } ) ) ;
148
198
entries . sort ( ( a , b ) => b . relevance - a . relevance ) ;
199
+ if ( ! verbose ) {
200
+ entries = entries . filter ( ( e ) => e . lowHigh < 1 || e . highLow > 1 ) ;
201
+ }
202
+ if ( threshold ) {
203
+ entries = entries . filter ( ( e ) => e . relevance >= threshold ) ;
204
+ }
205
+ if ( limit ) {
206
+ entries = entries . slice ( 0 , limit ) ;
207
+ }
149
208
const offset = ( factor ) => {
150
209
if ( factor > 10 ) return `${ Math . round ( factor * 10 ) / 10 } x` ;
151
- if ( factor > 1.1 ) return `+${ Math . round ( 100 - factor * 100 ) } %` ;
152
- if ( factor > 1 ) return `+${ Math . round ( 1000 - factor * 1000 ) / 10 } %` ;
210
+ if ( factor > 1.1 ) return `+${ Math . round ( factor * 100 - 100 ) } %` ;
211
+ if ( factor > 1 ) return `+${ Math . round ( factor * 1000 - 1000 ) / 10 } %` ;
153
212
if ( factor > 0.9 ) return `-${ Math . round ( 1000 - factor * 1000 ) / 10 } %` ;
154
213
return `-${ Math . round ( 100 - factor * 100 ) } %` ;
155
214
} ;
@@ -169,14 +228,17 @@ export const formatDiffTable = (diff, colors) => {
169
228
: "unclear" ,
170
229
name : ( l ) => l . name ,
171
230
mean : ( l ) => offset ( l . mean ) ,
172
- med : ( l ) => offset ( l . median ) ,
173
- min : ( l ) => offset ( l . min ) ,
174
- low : ( l ) => offset ( l . low ) ,
175
- high : ( l ) => offset ( l . high ) ,
176
- max : ( l ) => offset ( l . max ) ,
177
- std : ( l ) => offset ( l . stdDev ) ,
178
- baseStd : ( l ) => percentage ( l . baseStdDev ) ,
179
- curStd : ( l ) => percentage ( l . currentStdDev ) ,
231
+ ...( verbose
232
+ ? {
233
+ med : ( l ) => offset ( l . median ) ,
234
+ min : ( l ) => offset ( l . min ) ,
235
+ max : ( l ) => offset ( l . max ) ,
236
+ std : ( l ) => offset ( l . stdDev ) ,
237
+ con : ( l ) => offset ( l . confidence ) ,
238
+ }
239
+ : undefined ) ,
240
+ baseCon : ( l ) => percentage ( l . baseConfidence ) ,
241
+ curCon : ( l ) => percentage ( l . currentConfidence ) ,
180
242
} ;
181
243
const rows = entries . map ( ( entry ) =>
182
244
Object . keys ( columns ) . map ( ( key ) => columns [ key ] ( entry ) || "" )
@@ -195,7 +257,7 @@ export const formatDiffTable = (diff, colors) => {
195
257
...rows . map ( ( row ) => {
196
258
const line = getLine ( row ) ;
197
259
if ( colors ) {
198
- if ( row [ 1 ] . startsWith ( "+" ) )
260
+ if ( row [ 1 ] . startsWith ( "+" ) || row [ 1 ] . endsWith ( "x" ) )
199
261
return `\u001b[1m\u001b[31m${ line } \u001b[39m\u001b[22m` ;
200
262
if ( row [ 1 ] . startsWith ( "-" ) )
201
263
return `\u001b[1m\u001b[32m${ line } \u001b[39m\u001b[22m` ;
0 commit comments