Acme-CPANModules-TextTable
view release on metacpan or search on metacpan
lib/Acme/CPANModules/TextTable.pm view on Meta::CPAN
package Acme::CPANModules::TextTable;
use 5.010001;
use strict;
use warnings;
use utf8;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2023-10-31'; # DATE
our $DIST = 'Acme-CPANModules-TextTable'; # DIST
our $VERSION = '0.016'; # VERSION
sub _make_table {
my ($cols, $rows, $celltext) = @_;
my $res = [];
push @$res, [];
for (0..$cols-1) { $res->[0][$_] = "col" . ($_+1) }
for my $row (1..$rows) {
push @$res, [ map { $celltext // "row$row.$_" } 1..$cols ];
}
$res;
}
our $LIST = {
summary => 'List of modules that generate text tables',
description => <<'_',
Currently excluded from this list are:
- <pm:Text::SimpleTable::AutoWidth> (wrapper to <pm:Text::SimpleTable>);
- <pm:Text::ASCIITable::EasyTable> (wrapper to <pm:Text::ASCIITable>);
_
entry_features => {
wide_char => {summary => 'Whether the use of wide characters (e.g. Kanji) in cells does not cause the table to be misaligned'},
color_data => {summary => 'Whether module supports ANSI colors (i.e. text with ANSI color codes can still be aligned properly)'},
multiline_data => {summary => 'Whether module supports aligning data cells that contain newlines'},
box_char => {summary => 'Whether module can utilize box-drawing characters'},
custom_border => {summary => 'Whether module allows customizing border in some way'},
align_row => {summary => "Whether module supports aligning text horizontally in a row (left/right/middle)"},
align_column => {summary => "Whether module supports aligning text horizontally in a column (left/right/middle)"},
align_cell => {summary => "Whether module supports aligning text horizontally in individual cells (left/right/middle)"},
valign_row => {summary => "Whether module supports aligning text vertically in a row (top/bottom/middle)"},
valign_column => {summary => "Whether module supports aligning text vertically in a column (top/bottom/middle)"},
valign_cell => {summary => "Whether module supports aligning text vertically in individual cells (top/bottom/middle)"},
rowspan => {summary => "Whether module supports row spans"},
colspan => {summary => "Whether module supports column spans"},
custom_color => {summary => 'Whether the module produces colored table and supports customizing color in some way'},
color_theme => {summary => 'Whether the module supports color theme/scheme'},
speed => {summary => "Rendering speed", schema=>'str*'},
column_width => {summary => 'Whether module allows setting the width of columns'},
per_column_width => {summary => 'Whether module allows setting column width on a per-column basis'},
row_height => {summary => 'Whether module allows setting the height of rows'},
per_row_height => {summary => 'Whether module allows setting row height on a per-row basis'},
pad => {summary => 'Whether module allows customizing cell horizontal padding'},
vpad => {summary => 'Whether module allows customizing cell vertical padding'},
},
entries => [
lib/Acme/CPANModules/TextTable.pm view on Meta::CPAN
rowspan => 0,
wide_char_data => 1,
speed => "slow",
},
},
{
module => 'Text::Table::Manifold',
description => <<'_',
Two main features of this module is per-column aligning and wide character
support. This module, aside from doing its rendering, can also be told to pass
rendering to HTML, CSV, or other text table module like
<pm:Text::UnicodeBox::Table>); so in this way it is similar to
<pm:Text::Table::Any>.
_
bench_code => sub {
my ($table) = @_;
my $t = Text::Table::Manifold->new;
$t->headers($table->[0]);
$t->data([ @{$table}[1 .. $#{$table}] ]);
join("\n", @{$t->render(padding => 1)}) . "\n";
},
features => {
align_cell => 0,
align_column => 1,
box_char => undef, # ?
color_data => 1,
color_theme => 0,
colspan => 0,
custom_border => {value=>0, summary=>"But this module can pass rendering to other module like Text::UnicodeBox::Table"},
custom_color => 0,
multiline_data => 0,
rowspan => 0,
wide_char_data => 1,
},
},
{
module => 'Text::ANSITable',
description => <<'_',
This 2013 project was my take in creating a text table module that can handle
color, multiline text, wide characters. I also threw in various formatting
options, e.g. per-column/row/cell align/valign/pad/vpad, conditional formatting,
and so on. I even added a couple of features I never used: hiding rows and
specifying columns to display which can be in different order from the original
specified columns or can contain the same original columns multiple times. I
think this module offers the most formatting options on CPAN.
In early 2021, I needed colspan/rowspan and I implemented this in a new module:
<pm:Text::Table::Span> (later renamed to <pm:Text::Table::More>). I plan to add
this feature too to Text::ANSITable, but in the meantime I'm also adding more
formatting options which I need to Text::Table::More.
_
bench_code => sub {
my ($table) = @_;
my $t = Text::ANSITable->new(
use_utf8 => 0,
use_box_chars => 0,
use_color => 0,
columns => $table->[0],
border_style => 'ASCII::SingleLine',
);
$t->add_row($table->[$_]) for 1..@$table-1;
$t->draw;
},
features => {
align_cell => 1,
align_column => 1,
align_row => 1,
box_char => 1,
color_data => 1,
color_theme => 1,
colspan => 0,
column_width => 1,
custom_border => 1,
custom_color => 1,
multiline_data => 1,
pad => 1,
per_column_width => 1,
per_row_height => 1,
row_height => 1,
rowspan => 0,
speed => "slow",
valign_cell => 1,
valign_column => 1,
valign_row => 1,
vpad => 1,
wide_char_data => 1,
},
},
{
module => 'Text::ASCIITable',
bench_code => sub {
my ($table) = @_;
my $t = Text::ASCIITable->new();
$t->setCols(@{ $table->[0] });
$t->addRow(@{ $table->[$_] }) for 1..@$table-1;
"$t";
},
features => {
wide_char_data => 0,
color_data => 0,
box_char => 0,
multiline_data => 1,
},
},
{
module => 'Text::FormatTable',
bench_code => sub {
my ($table) = @_;
my $t = Text::FormatTable->new(join('|', ('l') x @{ $table->[0] }));
$t->head(@{ $table->[0] });
$t->row(@{ $table->[$_] }) for 1..@$table-1;
$t->render;
},
features => {
lib/Acme/CPANModules/TextTable.pm view on Meta::CPAN
| Text::Table::HTML::DataTables | 100 | 10 | 10410.10% | 239.35% | 0.00018 | 20 |
| Text::Table::TinyBorderStyle | 200 | 6 | 19509.01% | 81.89% | 0.00011 | 20 |
| Text::Table::Org | 200 | 5 | 20190.87% | 75.78% | 0.00013 | 20 |
| Text::Table::CSV | 200 | 4.9 | 21769.21% | 63.09% | 4.3e-05 | 20 |
| Text::Table::Sprintf | 300 | 4 | 28690.71% | 23.88% | 7.4e-05 | 20 |
| Text::Table::Any | 300 | 3 | 35566.44% | 0.00% | 3.3e-05 | 20 |
+-------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+
The above result formatted in L<Benchmark.pm|Benchmark> style:
Rate Text::UnicodeBox::Table Text::ANSITable Text::Table::More Text::ASCIITable Text::Table::TinyColorWide Text::FormatTable Text::Table::TinyWide Text::SimpleTable Text::Table::Manifold Text::Table::Tiny ...
Text::UnicodeBox::Table 0.92/s -- -49% -63% -90% -93% -93% -95% -96% -97% -97% ...
Text::ANSITable 1.8/s 96% -- -28% -82% -87% -87% -91% -93% -94% -94% ...
Text::Table::More 2.5/s 175% 39% -- -75% -82% -82% -87% -90% -92% -92% ...
Text::ASCIITable 9.6/s 1000% 459% 300% -- -30% -31% -50% -62% -70% -70% ...
Text::Table::TinyColorWide 10/s 1471% 700% 471% 42% -- -1% -28% -45% -57% -57% ...
Text::FormatTable 15/s 1494% 711% 479% 44% 1% -- -27% -44% -56% -56% ...
Text::Table::TinyWide 20/s 2100% 1019% 700% 100% 39% 37% -- -24% -40% -40% ...
Text::SimpleTable 26/s 2794% 1373% 952% 163% 84% 81% 31% -- -21% -21% ...
Text::Table::Manifold 30/s 3566% 1766% 1233% 233% 133% 129% 66% 26% -- 0% ...
Text::Table::Tiny 30/s 3566% 1766% 1233% 233% 133% 129% 66% 26% 0% -- ...
Text::TabularDisplay 40/s 3566% 1766% 1233% 233% 133% 129% 66% 26% 0% 0% ...
Text::Table::HTML 50/s 5400% 2700% 1900% 400% 250% 245% 150% 89% 50% 50% ...
Text::Table::TinyColor 50/s 5400% 2700% 1900% 400% 250% 245% 150% 89% 50% 50% ...
Text::MarkdownTable 60/s 5400% 2700% 1900% 400% 250% 245% 150% 89% 50% 50% ...
Text::Table 90/s 10900% 5500% 3900% 900% 600% 590% 400% 280% 200% 200% ...
Text::Table::HTML::DataTables 100/s 10900% 5500% 3900% 900% 600% 590% 400% 280% 200% 200% ...
Text::Table::TinyBorderStyle 200/s 18233% 9233% 6566% 1566% 1066% 1050% 733% 533% 400% 400% ...
Text::Table::Org 200/s 21900% 11100% 7900% 1900% 1300% 1280% 900% 660% 500% 500% ...
Text::Table::CSV 200/s 22348% 11328% 8063% 1940% 1328% 1308% 920% 675% 512% 512% ...
Text::Table::Sprintf 300/s 27400% 13900% 9900% 2400% 1650% 1625% 1150% 850% 650% 650% ...
Text::Table::Any 300/s 36566% 18566% 13233% 3233% 2233% 2200% 1566% 1166% 900% 900% ...
Legends:
Text::ANSITable: participant=Text::ANSITable
Text::ASCIITable: participant=Text::ASCIITable
Text::FormatTable: participant=Text::FormatTable
Text::MarkdownTable: participant=Text::MarkdownTable
Text::SimpleTable: participant=Text::SimpleTable
Text::Table: participant=Text::Table
Text::Table::Any: participant=Text::Table::Any
Text::Table::CSV: participant=Text::Table::CSV
Text::Table::HTML: participant=Text::Table::HTML
Text::Table::HTML::DataTables: participant=Text::Table::HTML::DataTables
Text::Table::Manifold: participant=Text::Table::Manifold
Text::Table::More: participant=Text::Table::More
Text::Table::Org: participant=Text::Table::Org
Text::Table::Sprintf: participant=Text::Table::Sprintf
Text::Table::Tiny: participant=Text::Table::Tiny
Text::Table::TinyBorderStyle: participant=Text::Table::TinyBorderStyle
Text::Table::TinyColor: participant=Text::Table::TinyColor
Text::Table::TinyColorWide: participant=Text::Table::TinyColorWide
Text::Table::TinyWide: participant=Text::Table::TinyWide
Text::TabularDisplay: participant=Text::TabularDisplay
Text::UnicodeBox::Table: participant=Text::UnicodeBox::Table
The above result presented as chart:
=begin html
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtAAAAH4CAMAAABUnipoAAAJJmlDQ1BpY2MAAEiJlZVnUJNZF8fv8zzphUASQodQQ5EqJYCUEFoo0quoQOidUEVsiLgCK4qINEWQRQEXXJUia0UUC4uCAhZ0gywCyrpxFVFBWXDfGZ33HT+8/5l7z2/+c+bec8/5cAEgiINlwct7YlK6wNvJjhkYFMwE3yiMn5...
=end html
Result formatted as table (split, part 2 of 5):
#table2#
{dataset=>"long (3x300)"}
+-------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+
| participant | rate (/s) | time (ms) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+-------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+
| Text::UnicodeBox::Table | 7.4 | 140 | 0.00% | 35069.88% | 0.0005 | 20 |
| Text::ANSITable | 17 | 58 | 132.94% | 14998.05% | 0.00043 | 21 |
| Text::Table::More | 21 | 49 | 178.85% | 12512.60% | 0.00046 | 20 |
| Text::ASCIITable | 100 | 10 | 1223.05% | 2558.25% | 0.00022 | 22 |
| Text::FormatTable | 100 | 8 | 1644.13% | 1916.47% | 0.00026 | 21 |
| Text::Table::TinyColorWide | 100 | 7 | 1789.53% | 1761.30% | 0.00016 | 20 |
| Text::Table::TinyWide | 200 | 5 | 2638.44% | 1184.31% | 6.1e-05 | 20 |
| Text::SimpleTable | 200 | 4 | 3188.50% | 969.48% | 8.7e-05 | 20 |
| Text::Table::Manifold | 300 | 3 | 3871.99% | 785.45% | 5.4e-05 | 21 |
| Text::TabularDisplay | 350 | 2.8 | 4714.43% | 630.51% | 8.9e-06 | 20 |
| Text::Table::Tiny | 380 | 2.7 | 4992.67% | 590.60% | 5.5e-06 | 20 |
| Text::MarkdownTable | 410 | 2.5 | 5417.46% | 537.43% | 6.7e-06 | 20 |
| Text::Table | 500 | 2 | 6071.61% | 469.87% | 3.6e-05 | 20 |
| Text::Table::TinyColor | 570 | 1.8 | 7628.23% | 355.08% | 4.2e-06 | 20 |
| Text::Table::HTML | 590 | 1.7 | 7913.19% | 338.90% | 3.4e-06 | 20 |
| Text::Table::HTML::DataTables | 890 | 1.1 | 12003.16% | 190.58% | 5.1e-06 | 20 |
| Text::Table::TinyBorderStyle | 1200 | 0.83 | 16229.83% | 115.37% | 6.6e-06 | 20 |
| Text::Table::Org | 1600 | 0.62 | 21670.38% | 61.55% | 6.6e-07 | 20 |
| Text::Table::CSV | 1730 | 0.579 | 23360.70% | 49.91% | 2.3e-07 | 20 |
| Text::Table::Any | 2500 | 0.4 | 33906.20% | 3.42% | 4.3e-07 | 20 |
| Text::Table::Sprintf | 2590 | 0.386 | 35069.88% | 0.00% | 1.6e-07 | 20 |
+-------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+
The above result formatted in L<Benchmark.pm|Benchmark> style:
Rate Text::UnicodeBox::Table Text::ANSITable Text::Table::More Text::ASCIITable Text::FormatTable Text::Table::TinyColorWide Text::Table::TinyWide Text::SimpleTable Text::Table::Manifold Text::TabularDispl...
Text::UnicodeBox::Table 7.4/s -- -58% -65% -92% -94% -95% -96% -97% -97% -9...
Text::ANSITable 17/s 141% -- -15% -82% -86% -87% -91% -93% -94% -9...
Text::Table::More 21/s 185% 18% -- -79% -83% -85% -89% -91% -93% -9...
Text::ASCIITable 100/s 1300% 480% 390% -- -19% -30% -50% -60% -70% -7...
Text::FormatTable 100/s 1650% 625% 512% 25% -- -12% -37% -50% -62% -6...
Text::Table::TinyColorWide 100/s 1900% 728% 600% 42% 14% -- -28% -42% -57% -6...
Text::Table::TinyWide 200/s 2700% 1060% 880% 100% 60% 39% -- -19% -40% -4...
Text::SimpleTable 200/s 3400% 1350% 1125% 150% 100% 75% 25% -- -25% -3...
Text::Table::Manifold 300/s 4566% 1833% 1533% 233% 166% 133% 66% 33% -- -...
Text::TabularDisplay 350/s 4900% 1971% 1650% 257% 185% 150% 78% 42% 7% ...
Text::Table::Tiny 380/s 5085% 2048% 1714% 270% 196% 159% 85% 48% 11% ...
Text::MarkdownTable 410/s 5500% 2220% 1860% 300% 220% 179% 100% 60% 19% 1...
Text::Table 500/s 6900% 2800% 2350% 400% 300% 250% 150% 100% 50% 3...
Text::Table::TinyColor 570/s 7677% 3122% 2622% 455% 344% 288% 177% 122% 66% 5...
Text::Table::HTML 590/s 8135% 3311% 2782% 488% 370% 311% 194% 135% 76% 6...
Text::Table::HTML::DataTables 890/s 12627% 5172% 4354% 809% 627% 536% 354% 263% 172% 15...
Text::Table::TinyBorderStyle 1200/s 16767% 6887% 5803% 1104% 863% 743% 502% 381% 261% 23...
Text::Table::Org 1600/s 22480% 9254% 7803% 1512% 1190% 1029% 706% 545% 383% 35...
Text::Table::CSV 1730/s 24079% 9917% 8362% 1627% 1281% 1108% 763% 590% 418% 38...
Text::Table::Any 2500/s 34900% 14400% 12150% 2400% 1900% 1650% 1150% 900% 650% 59...
Text::Table::Sprintf 2590/s 36169% 14925% 12594% 2490% 1972% 1713% 1195% 936% 677% 62...
Legends:
( run in 0.770 second using v1.01-cache-2.11-cpan-39bf76dae61 )