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:
- golang.org/pkg/text/tabwriter
- github.com/alexeyco/simpletable
- github.com/bndr/gotabulate
- github.com/cheynewallace/tabby
- github.com/gosuri/uitable
- github.com/jedib0t/go-pretty
- github.com/olekukonko/tablewriter
- github.com/palantir/pkg
- github.com/rodaine/table
- github.com/syohex/go-texttable
- github.com/tatsushid/go-prettytable
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 | ||||||||||||
Github popularity | language built-in | |||||||||||
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 | ❌ | ✔️ | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | ❌ | ❌ | ❌ |
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
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
# 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
+----+------------------+--------------+-----------------------------+------+
| # | 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 |
+----+------------------+--------------+-----------------------------+------+
+-------+---------------------+-----------------+--------------------------------+---------+
| # | 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 |
+-------+---------------------+-----------------+--------------------------------+---------+
# 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
# 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
# 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
+----+------------------+--------------+-----------------------------+------+
| # | 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 |
+----+------------------+--------------+-----------------------------+------+
+----+------------------+--------------+-----------------------------+------+
| # | 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 |
+----+------------------+--------------+-----------------------------+------+
# 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
# 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
+----+------------------+--------------+-----------------------------+------+
| # | 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 |
+----+------------------+--------------+-----------------------------+------+
# | 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
In case something is missing or incorrect, please file an issue or raise a pull request.