Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric table columns in report should be aligned right #975

Open
donquixote opened this issue Jan 2, 2022 · 3 comments
Open

Numeric table columns in report should be aligned right #975

donquixote opened this issue Jan 2, 2022 · 3 comments

Comments

@donquixote
Copy link

In a cli report table, to properly compare numbers, columns with numbers should:

  • be aligned right (\STR_PAD_LEFT).
  • use the same measuring unit (e.g. not ms in one record, but µs in another record).
  • ideally, a unit should be used where all values are > 1, so that big numbers visually stick out with additional digits to the left.
    (for these last points I currently use --mode=throughput --time-unit=s as cli parameters)

For the first point, I found that the following addition in TableRenderer::render() has the desired effect for the main table:

        $style = (new TableStyle())->setPadType(\STR_PAD_LEFT);
        $nColumns = \count($object->columnNames());
        for ($iCol = 2; $iCol < $nColumns; ++$iCol) {
            $consoleTable->setColumnStyle($iCol, $style);
        }

However, this is obviously the wrong place to do this.
I am hard-coding the rule that every column except the first two should be aligned right, which is true for the final overview table but not universally for every table.

What the code example shows is that the symfony console table component can align numbers right.

@donquixote
Copy link
Author

Another way to do this would be per table cell.
https://symfony.com/doc/current/components/console/helpers/table.html
Perhaps we could check if the $node is a number, and then decide the alignment?

@donquixote
Copy link
Author

use the same measuring unit

If we do this, we also have the option to print the unit in the column title, e.g. "max (ms/s)", and pure numbers in the cells.
I would say this is a little bit less readable in the cli output, but makes it easier to copy + paste and reuse this data for a spreadsheet, with some find/replace.

Although for this perhaps a dedicated csv output is preferable. I have not figured out how to do this in combination with --report=overview option.

@dantleech
Copy link
Member

use the same measuring unit

https://phpbench.readthedocs.io/en/latest/configuration.html#runner-time-unit

Perhaps we could check if the $node is a number, and then decide the alignment?

Could do that here:

$consoleTable->setRows($this->buildRows($object));

reuse this data for a spreadsheet

There is an output for that: --output=csv:

suite,date,php,"vcs branch",xdebug,iterations,revs,mode,net_time
<current>,"2022-01-02 10:39:18",8.1.0,remove-trailing-zero,,90,900,2.739530332681,34470

we also have the option to print the unit in the column titl

probably this boilds down to be able to configure the individual renderers (e.g. show unit or not, align numbers to the right)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants