Skip to content

Commit 677b59c

Browse files
committed
[process-stats-dir] Format times and numbers nicely in --markdown mode.
1 parent a47055e commit 677b59c

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

utils/process-stats-dir.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,20 @@ def write_comparison(args, old_stats, new_stats):
311311

312312
if args.markdown:
313313

314+
def format_time(v):
315+
if abs(v) > 1000000:
316+
return "{:.1f}s".format(v / 1000000.0)
317+
elif abs(v) > 1000:
318+
return "{:.1f}ms".format(v / 1000.0)
319+
else:
320+
return "{:.1f}us".format(v)
321+
314322
def format_field(field, row):
315-
if field == 'name' and args.group_by_module:
316-
return stat_name_minus_module(row.name)
323+
if field == 'name':
324+
if args.group_by_module:
325+
return stat_name_minus_module(row.name)
326+
else:
327+
return row.name
317328
elif field == 'delta_pct':
318329
s = str(row.delta_pct) + "%"
319330
if args.github_emoji:
@@ -323,7 +334,11 @@ def format_field(field, row):
323334
s += " :white_check_mark:"
324335
return s
325336
else:
326-
return str(vars(row)[field])
337+
v = int(vars(row)[field])
338+
if row.name.startswith('time.'):
339+
return format_time(v)
340+
else:
341+
return "{:,d}".format(v)
327342

328343
def format_table(elts):
329344
out = args.output
@@ -360,10 +375,12 @@ def keyfunc(e):
360375
format_table(elts)
361376
out.write('</details>\n')
362377

363-
format_details('Regressed', regressed, args.close_regressions)
378+
closed_regressions = (args.close_regressions or len(regressed) == 0)
379+
format_details('Regressed', regressed, closed_regressions)
364380
format_details('Improved', improved, True)
365-
format_details('Unchanged (abs(delta) < %s%% or %susec)' %
366-
(args.delta_pct_thresh, args.delta_usec_thresh),
381+
format_details('Unchanged (delta < %s%% or delta < %s)' %
382+
(args.delta_pct_thresh,
383+
format_time(args.delta_usec_thresh)),
367384
unchanged, True)
368385

369386
else:

0 commit comments

Comments
 (0)