go-table-comparison

command module
v0.0.0-...-c7ee8b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README ΒΆ

Go Table Library Comparison

There are several libraries for rending tables in console applications written Go. However, it's difficult to compare their features as well as their performance.

Below you can find an subjective overview of several table rendering libraries:

Feature Comparison

Please note that the absence of a feature does not mean that there is no support at all.

For example, many libraries don't have color support built-in but are compatible with common ANSI color libraries.

Feature tabwriter alexeyco bndr caarlos0 cheynewallace gosuri jedib0t olekukonko palantir rodaine syohex tatsushid
Github last commit c_alexeyco c_bndr c_caarlos0 c_cheynewallace c_gosuri c_jedib0t c_olekukonko c_palantir c_rodaine c_syohex c_tatsushid
Github popularity language built-in s_alexeyco s_bndr s_caarlos0 s_cheynewallace s_gosuri s_jedib0t s_olekukonko s_palantir s_rodaine s_syohex s_tatsushid
performance βœ” πŸ”Ή βœ” πŸ”Ή βœ” ❌ βœ” πŸ”Ή βœ” βœ” βœ” βœ”
built-in colors βœ” ❌ ❌ ❌ ❌ ❌ βœ” βœ” ❌ ❌ ❌ ❌
predefined styles ❌ βœ” βœ” ❌ ❌ ❌ βœ” ❌ ❌ ❌ ❌ ❌
custom styles ❌ βœ” ❌ ❌ ❌ ❌ βœ” βœ” ❌ ❌ ❌ βœ”
align text πŸ”Ή βœ” πŸ”Ή πŸ”Ή πŸ”Ή πŸ”Ή βœ” βœ” πŸ”Ή ❌ ❌ βœ”
borders πŸ”Ή βœ” βœ” πŸ”Ή πŸ”Ή ❌ βœ” βœ” πŸ”Ή ❌ ❌ ❌
cell span ❌ βœ” ❌ ❌ ❌ ❌ βœ” βœ” ❌ ❌ ❌ ❌
custom renderer ❌ βœ” ❌ βœ” ❌ ❌ βœ” βœ” ❌ πŸ”Ή ❌ ❌
footer ❌ βœ” ❌ ❌ ❌ ❌ βœ” βœ” ❌ ❌ ❌ ❌
multiline ❌ βœ” βœ” ❌ ❌ ❌ βœ” βœ” ❌ ❌ ❌ ❌
string values βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ”
interface values βœ” ❌ βœ” βœ” βœ” βœ” βœ” ❌ βœ” βœ” ❌ βœ”
arbitrary structs ❌ ❌ ❌ βœ” ❌ ❌ ❌ ❌ βœ” ❌ ❌ ❌
ASCII output βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ” βœ”
CSV output ❌ ❌ ❌ ❌ ❌ ❌ βœ” ❌ ❌ ❌ ❌ ❌
HTML output ❌ ❌ ❌ ❌ ❌ ❌ βœ” ❌ ❌ ❌ ❌ ❌
Markdown output ❌ βœ” ❌ ❌ ❌ ❌ βœ” ❌ ❌ ❌ ❌ ❌

Benchmark

The benchmark is taken from alexeyco and adjusted for the libraries, if necessary.

All libraries show similar characteristics in terms of number of rows i.e., the time increases linearly with the number of rows (tested up to 1000). However, the performance might be different for dozens of columns. Furthermore, the impact of advanced features such as cell spanning, multi-line, custom formatters, etc. are not reflected in the benchmark since those features are not implemented by all libraries. Thus, the benchmark implements a rather "simple" use case of five columns with strings and numbers.

The benchmark can be executed as follows:

go test ./... -bench . -benchmem -benchtime 10000x
go test ./... -bench . -benchmem -benchtime 10000x
?       github.com/gschauer/go-table-comparison [no test files]
goos: darwin
goarch: arm64
pkg: github.com/gschauer/go-table-comparison/simple
BenchmarkAlexeyCo-10               10000            125782 ns/op           63461 B/op       1418 allocs/op
BenchmarkBndr-10                   10000             23313 ns/op           36994 B/op        536 allocs/op
BenchmarkCaarlos0-10               10000              6747 ns/op            8708 B/op         86 allocs/op
BenchmarkCheyneWallace-10          10000              7392 ns/op            8708 B/op         72 allocs/op
BenchmarkGOsuri-10                 10000            276073 ns/op          117436 B/op       3532 allocs/op
BenchmarkJedib0t-10                10000             36386 ns/op           11005 B/op        310 allocs/op
BenchmarkOlekuKonko-10             10000            102845 ns/op           46892 B/op       1196 allocs/op
BenchmarkPalantir-10               10000              8057 ns/op           10677 B/op         93 allocs/op
BenchmarkRodaine-10                10000             10062 ns/op            8820 B/op        245 allocs/op
BenchmarkSyohex-10                 10000             82481 ns/op           47804 B/op        999 allocs/op
BenchmarkTabWriter-10              10000              5971 ns/op            7715 B/op         40 allocs/op
BenchmarkTatsushiD-10              10000             66908 ns/op           34240 B/op        481 allocs/op
PASS
ok      github.com/gschauer/go-table-comparison/simple  7.990s

Example Output

The output of many libraries can be highly customized. The following listing shows whether they have sensible defaults in terms of output configuration.

In order to see the default output format of all implementations, run

go run main.go
text/tabwriter
#     NAME              PHONE         EMAIL                        QTTY
----  ----              ----          ----                         ----
1     Newton G. Goetz   252-585-5166  NewtonGGoetz@dayrep.com      10
2     Rebecca R. Edney  865-475-4171  RebeccaREdney@armyspy.com    12
3     John R. Jackson   810-325-1417  JohnRJackson@armyspy.com     15
github.com/alexeyco/simpletable
+----+------------------+--------------+-----------------------------+------+
| #  | NAME             | PHONE        | EMAIL                       | QTTY |
+----+------------------+--------------+-----------------------------+------+
| 1  | Newton G. Goetz  | 252-585-5166 | NewtonGGoetz@dayrep.com     | 10   |
| 2  | Rebecca R. Edney | 865-475-4171 | RebeccaREdney@armyspy.com   | 12   |
| 3  | John R. Jackson  | 810-325-1417 | JohnRJackson@armyspy.com    | 15   |
+----+------------------+--------------+-----------------------------+------+
github.com/bndr/gotabulate
+-------+---------------------+-----------------+--------------------------------+---------+
|     # |                NAME |           PHONE |                          EMAIL |    QTTY |
+=======+=====================+=================+================================+=========+
|     1 |     Newton G. Goetz |    252-585-5166 |        NewtonGGoetz@dayrep.com |      10 |
+-------+---------------------+-----------------+--------------------------------+---------+
|     2 |    Rebecca R. Edney |    865-475-4171 |      RebeccaREdney@armyspy.com |      12 |
+-------+---------------------+-----------------+--------------------------------+---------+
|     3 |     John R. Jackson |    810-325-1417 |       JohnRJackson@armyspy.com |      15 |
+-------+---------------------+-----------------+--------------------------------+---------+
github.com/caarlos0/tablewriter
#        NAME                PHONE           EMAIL                          QTTY
1        Newton G. Goetz     252-585-5166    NewtonGGoetz@dayrep.com        10
2        Rebecca R. Edney    865-475-4171    RebeccaREdney@armyspy.com      12
3        John R. Jackson     810-325-1417    JohnRJackson@armyspy.com       15
github.com/cheynewallace/tabby
#   NAME              PHONE         EMAIL                        QTTY
-   ----              -----         -----                        ----
1   Newton G. Goetz   252-585-5166  NewtonGGoetz@dayrep.com      10
2   Rebecca R. Edney  865-475-4171  RebeccaREdney@armyspy.com    12
3   John R. Jackson   810-325-1417  JohnRJackson@armyspy.com     15
github.com/gosuri/uitable
#       NAME                    PHONE           EMAIL                           QTTY
1       Newton G. Goetz         252-585-5166    NewtonGGoetz@dayrep.com         10
2       Rebecca R. Edney        865-475-4171    RebeccaREdney@armyspy.com       12
3       John R. Jackson         810-325-1417    JohnRJackson@armyspy.com        15
github.com/jedib0t/go-pretty
+----+------------------+--------------+-----------------------------+------+
|  # | NAME             | PHONE        | EMAIL                       | QTTY |
+----+------------------+--------------+-----------------------------+------+
|  1 | Newton G. Goetz  | 252-585-5166 | NewtonGGoetz@dayrep.com     |   10 |
|  2 | Rebecca R. Edney | 865-475-4171 | RebeccaREdney@armyspy.com   |   12 |
|  3 | John R. Jackson  | 810-325-1417 | JohnRJackson@armyspy.com    |   15 |
+----+------------------+--------------+-----------------------------+------+
github.com/olekukonko/tablewriter
+----+------------------+--------------+-----------------------------+------+
| #  |       NAME       |    PHONE     |            EMAIL            | QTTY |
+----+------------------+--------------+-----------------------------+------+
|  1 | Newton G. Goetz  | 252-585-5166 | NewtonGGoetz@dayrep.com     |   10 |
|  2 | Rebecca R. Edney | 865-475-4171 | RebeccaREdney@armyspy.com   |   12 |
|  3 | John R. Jackson  | 810-325-1417 | JohnRJackson@armyspy.com    |   15 |
+----+------------------+--------------+-----------------------------+------+
github.com/palantir/pkg/tableprinter
#   NAME              PHONE         EMAIL                        QTTY
-   ----              -----         -----                        ----
1   Newton G. Goetz   252-585-5166  NewtonGGoetz@dayrep.com      10
2   Rebecca R. Edney  865-475-4171  RebeccaREdney@armyspy.com    12
3   John R. Jackson   810-325-1417  JohnRJackson@armyspy.com     15
github.com/rodaine/table
#   NAME              PHONE         EMAIL                        QTTY
1   Newton G. Goetz   252-585-5166  NewtonGGoetz@dayrep.com      10
2   Rebecca R. Edney  865-475-4171  RebeccaREdney@armyspy.com    12
3   John R. Jackson   810-325-1417  JohnRJackson@armyspy.com     15
github.com/syohex/go-texttable
+----+------------------+--------------+-----------------------------+------+
| #  | NAME             | PHONE        | EMAIL                       | QTTY |
+----+------------------+--------------+-----------------------------+------+
|  1 | Newton G. Goetz  | 252-585-5166 | NewtonGGoetz@dayrep.com     |   10 |
|  2 | Rebecca R. Edney | 865-475-4171 | RebeccaREdney@armyspy.com   |   12 |
|  3 | John R. Jackson  | 810-325-1417 | JohnRJackson@armyspy.com    |   15 |
+----+------------------+--------------+-----------------------------+------+
github.com/tatsushid/go-prettytable
#  | NAME             | PHONE        | EMAIL                       | QTTY
1  | Newton G. Goetz  | 252-585-5166 | NewtonGGoetz@dayrep.com     | 10
2  | Rebecca R. Edney | 865-475-4171 | RebeccaREdney@armyspy.com   | 12
3  | John R. Jackson  | 810-325-1417 | JohnRJackson@armyspy.com    | 15

Disclaimer

In case something is missing or incorrect, please file an issue or raise a pull request.

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL