File tree Expand file tree Collapse file tree 2 files changed +50
-9
lines changed Expand file tree Collapse file tree 2 files changed +50
-9
lines changed Original file line number Diff line number Diff line change @@ -148,11 +148,52 @@ function floatStr(n: number) {
148148 return n . toString ( ) ;
149149}
150150
151+ const round = ( n : number , places = 3 ) : number => parseFloat ( n . toFixed ( places ) ) ;
152+
153+ function strDuration ( n : number ) : string {
154+ let unit = 'ns' ;
155+ if ( n >= 6e10 ) {
156+ let secs = n / 1e9 ;
157+ const mins = Math . floor ( secs / 60 ) ;
158+ secs %= 60 ;
159+ return `${ mins } m ${ round ( secs ) } s` ;
160+ }
161+
162+ if ( n >= 1e9 ) {
163+ unit = 's' ;
164+ n /= 1e9 ;
165+ } else if ( n >= 1e6 ) {
166+ unit = 'ms' ;
167+ n /= 1e6 ;
168+ } else if ( n >= 1e3 ) {
169+ unit = 'μs' ;
170+ n /= 1e3 ;
171+ }
172+
173+ return `${ round ( n ) } ${ unit } ` ;
174+ }
175+
176+ const NS_RANGE_REGEX = / ^ ± \s * ( [ 0 - 9 ] + ) $ / ;
177+
151178function strVal ( b : BenchmarkResult ) : string {
152- let s = `\`${ b . value } \` ${ b . unit } ` ;
153- if ( b . range ) {
154- s += ` (\`${ b . range } \`)` ;
179+ let s = '' ;
180+ let range = b . range ;
181+
182+ if ( b . unit === 'ns/iter' ) {
183+ s += `\`${ strDuration ( b . value ) } /iter\`` ;
184+ range = range && range . match ( NS_RANGE_REGEX ) ?
185+ "± " + strDuration ( parseInt ( range . replace ( NS_RANGE_REGEX , "$1" ) ) ) :
186+ // If we can't show a unit, just give up...
187+ range = undefined ;
188+ }
189+ } else {
190+ s += `\`${ b . value } ${ b . unit } \`` ;
155191 }
192+
193+ if ( range ) {
194+ s += `<br>(\`${ range } \`)` ;
195+ }
196+
156197 return s ;
157198}
158199
Original file line number Diff line number Diff line change @@ -111,9 +111,9 @@ describe('buildComment', () => {
111111
112112 | Benchmark suite | Current: testCommitIdCurrent | Previous: testCommitIdPrevious | Ratio |
113113 |-|-|-|-|
114- | \`TestBench<1>\` | \`0\` testUnit | \`0\` testUnit | \`1\` |
115- | \`TestBench<2>\` | \`1\` testUnit | \`0\` testUnit | \`+∞\` |
116- | \`TestBench<3>\` | \`-1\` testUnit | \`0\` testUnit | \`-∞\` |
114+ | \`TestBench<1>\` | \`0 testUnit \` | \`0 testUnit\` | \`1\` |
115+ | \`TestBench<2>\` | \`1 testUnit \` | \`0 testUnit\` | \`+∞\` |
116+ | \`TestBench<3>\` | \`-1 testUnit \` | \`0 testUnit\` | \`-∞\` |
117117
118118 </details>
119119
@@ -197,9 +197,9 @@ describe('buildComment', () => {
197197
198198 | Benchmark suite | Current: testCommitIdCurrent | Previous: testCommitIdPrevious | Ratio |
199199 |-|-|-|-|
200- | \`TestBench<1>\` | \`0\` testUnit | \`0\` testUnit | \`1\` |
201- | \`TestBench<2>\` | \`0\` testUnit | \`1\` testUnit | \`+∞\` |
202- | \`TestBench<3>\` | \`0\` testUnit | \`-1\` testUnit | \`-∞\` |
200+ | \`TestBench<1>\` | \`0 testUnit \` | \`0 testUnit\` | \`1\` |
201+ | \`TestBench<2>\` | \`0 testUnit \` | \`1 testUnit\` | \`+∞\` |
202+ | \`TestBench<3>\` | \`0 testUnit \` | \`-1 testUnit\` | \`-∞\` |
203203
204204 </details>
205205
You can’t perform that action at this time.
0 commit comments