Skip to content

comparison of common table rendering libraries written in Go

License

Notifications You must be signed in to change notification settings

gschauer/go-table-comparison

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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  [email protected]      10
2     Rebecca R. Edney  865-475-4171  [email protected]    12
3     John R. Jackson   810-325-1417  [email protected]     15

github.com/alexeyco/simpletable

+----+------------------+--------------+-----------------------------+------+
| #  | NAME             | PHONE        | EMAIL                       | QTTY |
+----+------------------+--------------+-----------------------------+------+
| 1  | Newton G. Goetz  | 252-585-5166 | [email protected]     | 10   |
| 2  | Rebecca R. Edney | 865-475-4171 | [email protected]   | 12   |
| 3  | John R. Jackson  | 810-325-1417 | [email protected]    | 15   |
+----+------------------+--------------+-----------------------------+------+

github.com/bndr/gotabulate

+-------+---------------------+-----------------+--------------------------------+---------+
|     # |                NAME |           PHONE |                          EMAIL |    QTTY |
+=======+=====================+=================+================================+=========+
|     1 |     Newton G. Goetz |    252-585-5166 |        [email protected] |      10 |
+-------+---------------------+-----------------+--------------------------------+---------+
|     2 |    Rebecca R. Edney |    865-475-4171 |      [email protected] |      12 |
+-------+---------------------+-----------------+--------------------------------+---------+
|     3 |     John R. Jackson |    810-325-1417 |       [email protected] |      15 |
+-------+---------------------+-----------------+--------------------------------+---------+

github.com/caarlos0/tablewriter

#        NAME                PHONE           EMAIL                          QTTY
1        Newton G. Goetz     252-585-5166    [email protected]        10
2        Rebecca R. Edney    865-475-4171    [email protected]      12
3        John R. Jackson     810-325-1417    [email protected]       15

github.com/cheynewallace/tabby

#   NAME              PHONE         EMAIL                        QTTY
-   ----              -----         -----                        ----
1   Newton G. Goetz   252-585-5166  [email protected]      10
2   Rebecca R. Edney  865-475-4171  [email protected]    12
3   John R. Jackson   810-325-1417  [email protected]     15

github.com/gosuri/uitable

#       NAME                    PHONE           EMAIL                           QTTY
1       Newton G. Goetz         252-585-5166    [email protected]         10
2       Rebecca R. Edney        865-475-4171    [email protected]       12
3       John R. Jackson         810-325-1417    [email protected]        15

github.com/jedib0t/go-pretty

+----+------------------+--------------+-----------------------------+------+
|  # | NAME             | PHONE        | EMAIL                       | QTTY |
+----+------------------+--------------+-----------------------------+------+
|  1 | Newton G. Goetz  | 252-585-5166 | [email protected]     |   10 |
|  2 | Rebecca R. Edney | 865-475-4171 | [email protected]   |   12 |
|  3 | John R. Jackson  | 810-325-1417 | [email protected]    |   15 |
+----+------------------+--------------+-----------------------------+------+

github.com/olekukonko/tablewriter

+----+------------------+--------------+-----------------------------+------+
| #  |       NAME       |    PHONE     |            EMAIL            | QTTY |
+----+------------------+--------------+-----------------------------+------+
|  1 | Newton G. Goetz  | 252-585-5166 | [email protected]     |   10 |
|  2 | Rebecca R. Edney | 865-475-4171 | [email protected]   |   12 |
|  3 | John R. Jackson  | 810-325-1417 | [email protected]    |   15 |
+----+------------------+--------------+-----------------------------+------+

github.com/palantir/pkg/tableprinter

#   NAME              PHONE         EMAIL                        QTTY
-   ----              -----         -----                        ----
1   Newton G. Goetz   252-585-5166  [email protected]      10
2   Rebecca R. Edney  865-475-4171  [email protected]    12
3   John R. Jackson   810-325-1417  [email protected]     15

github.com/rodaine/table

#   NAME              PHONE         EMAIL                        QTTY
1   Newton G. Goetz   252-585-5166  [email protected]      10
2   Rebecca R. Edney  865-475-4171  [email protected]    12
3   John R. Jackson   810-325-1417  [email protected]     15

github.com/syohex/go-texttable

+----+------------------+--------------+-----------------------------+------+
| #  | NAME             | PHONE        | EMAIL                       | QTTY |
+----+------------------+--------------+-----------------------------+------+
|  1 | Newton G. Goetz  | 252-585-5166 | [email protected]     |   10 |
|  2 | Rebecca R. Edney | 865-475-4171 | [email protected]   |   12 |
|  3 | John R. Jackson  | 810-325-1417 | [email protected]    |   15 |
+----+------------------+--------------+-----------------------------+------+

github.com/tatsushid/go-prettytable

#  | NAME             | PHONE        | EMAIL                       | QTTY
1  | Newton G. Goetz  | 252-585-5166 | [email protected]     | 10
2  | Rebecca R. Edney | 865-475-4171 | [email protected]   | 12
3  | John R. Jackson  | 810-325-1417 | [email protected]    | 15

Disclaimer

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

About

comparison of common table rendering libraries written in Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published