Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2017, Intel Corporation. |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5 | # |
| 6 | """Build performance test library functions""" |
| 7 | |
| 8 | def print_table(rows, row_fmt=None): |
| 9 | """Print data table""" |
| 10 | if not rows: |
| 11 | return |
| 12 | if not row_fmt: |
| 13 | row_fmt = ['{:{wid}} '] * len(rows[0]) |
| 14 | |
| 15 | # Go through the data to get maximum cell widths |
| 16 | num_cols = len(row_fmt) |
| 17 | col_widths = [0] * num_cols |
| 18 | for row in rows: |
| 19 | for i, val in enumerate(row): |
| 20 | col_widths[i] = max(col_widths[i], len(str(val))) |
| 21 | |
| 22 | for row in rows: |
| 23 | print(*[row_fmt[i].format(col, wid=col_widths[i]) for i, col in enumerate(row)]) |
| 24 | |