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

feat: support streaming rendering #27

Merged
merged 18 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
- { os: ubuntu-latest , target: x86_64-unknown-linux-gnu , use-cross: use-cross }
- { os: ubuntu-latest , target: x86_64-unknown-linux-musl , use-cross: use-cross }
- { os: macos-latest , target: x86_64-apple-darwin }
# - { os: windows-latest , target: i686-pc-windows-msvc }
- { os: windows-latest , target: x86_64-pc-windows-msvc }
steps:
- name: Git checkout
Expand Down Expand Up @@ -137,15 +136,11 @@ jobs:
mkdir -p tmp
printf 'a,b,c\n1,2,3\n4,5,6\n7,8,9' > tmp/demo.csv

- name: Info
shell: bash
run: |
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
- name: Setup toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Build
uses: actions-rs/cargo@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
/.idea
/flamegraph.svg
/perf.data
110 changes: 11 additions & 99 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ clap_complete = "3"
strum = { version = "0.23", features = ["derive"] }
exitcode = "1.1"
anyhow = "1.0"
prettytable-rs = "0.8"
unicode-width = "0"
unicode-truncate = "0"

[build-dependencies]
clap = { version = "3", features = ["wrap_help", "derive"] }
Expand All @@ -35,6 +36,3 @@ strum = { version = "0.23", features = ["derive"] }
[profile.release]
lto = true
codegen-units = 1

[patch.crates-io]
prettytable-rs = { git = "https://github.com/wfxr/prettytable-rs" }
58 changes: 26 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
### Features

* Small and *fast* (see [benchmarks](#benchmark) below).
* Correctly handles CJK characters and emoji.
* Support different styles.
* Memory efficient.
* Correctly align [CJK](https://en.wikipedia.org/wiki/CJK_characters) and emoji characters.
* Support `tsv` and custom delimiters.
* Able to generate markdown table (with `--style markdown` option).
* Support different styles, including markdown table.

### Usage
```
Expand Down Expand Up @@ -113,7 +113,7 @@ Pre-built versions of `csview` for various architectures are available at [Githu

#### From source

`csview` is also published on [crates.io](https://crates.io). If you have Rust toolchains (1.40 or above) installed you can use `cargo` to install it from source:
`csview` is also published on [crates.io](https://crates.io). If you have Rust toolchains (nightly) installed you can use `cargo` to install it from source:

```
cargo install --locked csview
Expand All @@ -123,45 +123,39 @@ If you want the latest version, clone this repository and run `cargo build --rel

### Benchmark

Compared with `csvlook` provided by [csvkit](https://github.com/wireservice/csvkit/tree/1.0.5):
- [small.csv](https://gist.github.com/wfxr/567e890d4db508b3c7630a96b703a57e#file-action-csv) (10 rows, 4 cols, 695 bytes):

- [sample.csv](https://gist.github.com/wfxr/567e890d4db508b3c7630a96b703a57e#file-sample-csv) (10000 rows, 10 cols, 624K size):
| Tool | Command | Mean Time | Min Time | Memory |
|------------------------------------------------------------------------------------------|---------------------------|----------:|----------:|----------:|
| [csview](https://github.com/wfxr/csview/commit/d77a5b0fe5b10ebd9900c392585b314b0f1d09b2) | `csview small.csv` | **0.3ms** | **0.1ms** | **2.4mb** |
| [xsv](https://github.com/BurntSushi/xsv/tree/0.13.0) | `xsv table small.csv` | 2.0ms | 1.8ms | 3.9mb |
| [column](https://github.com/util-linux/util-linux/blob/stable/v2.37/text-utils/column.c) | `column -s, -t small.csv` | 1.3ms | 1.1ms | **2.4mb** |
| [csvlook](https://github.com/wireservice/csvkit/tree/1.0.6) | `csvlook small.csv` | 148.1ms | 142.4ms | 27.3mb |

```
Benchmark #1: csvlook sample.csv
Time (mean ± σ): 4.010 s ± 0.100 s [User: 3.945 s, System: 0.051 s]
Range (min … max): 3.911 s … 4.249 s 10 runs

Benchmark #2: csview sample.csv
Time (mean ± σ): 46.5 ms ± 2.3 ms [User: 39.7 ms, System: 6.5 ms]
Range (min … max): 44.0 ms … 59.4 ms 59 runs

Summary
'csview sample.csv' ran
86.32 ± 4.83 times faster than 'csvlook sample.csv'
```
- [medium.csv](https://gist.github.com/wfxr/567e890d4db508b3c7630a96b703a57e#file-sample-csv) (10,000 rows, 10 cols, 624K bytes):

- [action.csv](https://gist.github.com/wfxr/567e890d4db508b3c7630a96b703a57e#file-action-csv) (10 rows, 4 cols, 1K size):
```
Benchmark #1: csvlook action.csv
Time (mean ± σ): 316.5 ms ± 5.2 ms [User: 284.8 ms, System: 35.0 ms]
Range (min … max): 309.3 ms … 326.2 ms 10 runs
| Tool | Command | Mean Time | Min Time | Memory |
|------------------------------------------------------------------------------------------|---------------------------|-----------:|-----------:|----------:|
| [csview](https://github.com/wfxr/csview/commit/d77a5b0fe5b10ebd9900c392585b314b0f1d09b2) | `csview medium.csv` | **0.017s** | **0.016s** | **2.8mb** |
| [xsv](https://github.com/BurntSushi/xsv/tree/0.13.0) | `xsv table medium.csv` | 0.031s | 0.029s | 4.4mb |
| [column](https://github.com/util-linux/util-linux/blob/stable/v2.37/text-utils/column.c) | `column -s, -t small.csv` | 51.8ms | 49.8ms | 9.9mb |
| [csvlook](https://github.com/wireservice/csvkit/tree/1.0.6) | `csvlook medium.csv` | 2.664s | 2.617s | 46.8mb |

Benchmark #2: csview action.csv
Time (mean ± σ): 0.7 ms ± 0.2 ms [User: 0.8 ms, System: 0.7 ms]
Range (min … max): 0.4 ms … 1.6 ms 933 runs
- `large.csv` (generated by concatenating [medium.csv](https://gist.github.com/wfxr/567e890d4db508b3c7630a96b703a57e#file-sample-csv) 100 times, 1,000,000 rows, 10 cols, 61M bytes):

Summary
'csview action.csv' ran
461.25 ± 109.34 times faster than 'csvlook action.csv'
```
| Tool | Command | Mean Time | Min Time | Memory |
|------------------------------------------------------------------------------------------|---------------------------|-----------:|-----------:|----------:|
| [csview](https://github.com/wfxr/csview/commit/d77a5b0fe5b10ebd9900c392585b314b0f1d09b2) | `csview large.csv` | **1.686s** | **1.665s** | **2.8mb** |
| [xsv](https://github.com/BurntSushi/xsv/tree/0.13.0) | `xsv table large.csv` | 2.912s | 2.820s | 4.4mb |
| [column](https://github.com/util-linux/util-linux/blob/stable/v2.37/text-utils/column.c) | `column -s, -t small.csv` | 5.777ms | 5.759s | 767.6mb |
| [csvlook](https://github.com/wireservice/csvkit/tree/1.0.6) | `csvlook large.csv` | 20.665s | 20.549s | 1105.7mb |

### F.A.Q.

---
#### We already have [xsv](https://github.com/BurntSushi/xsv), why not contribute to it but build a new tool?

`xsv` is an awesome csv toolkit. It's aimed for analyzing and manipulating csv data.
`xsv` is great. But it's aimed for analyzing and manipulating csv data.
`csview` is designed for formatting and viewing. See also: [xsv/issues/156](https://github.com/BurntSushi/xsv/issues/156)

---
Expand Down
26 changes: 25 additions & 1 deletion completions/bash/csview.bash

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions completions/elvish/csview.elv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion completions/fish/csview.fish

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions completions/powershell/_csview.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading