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

Explore: tpretty implementation in awk? #13

Open
pavlov99 opened this issue Jun 22, 2020 · 3 comments
Open

Explore: tpretty implementation in awk? #13

pavlov99 opened this issue Jun 22, 2020 · 3 comments

Comments

@pavlov99
Copy link
Member

At the moment pretty table print is implemented in python. The program reads the whole input twice: one to calculate column widths and the second time to actually print.

Is it possible to implement such functionality in bash with reasonable limitations (e.g. header manipulation)?

See
https://superuser.com/questions/557256/reading-the-same-stdin-with-two-commands-in-bash

command1 source | tee >(command2) >(command3)

https://stackoverflow.com/questions/10218103/os-x-linux-pipe-into-two-processes

echo "Leeroy Jenkins" | tee >(md5sum > out1) >(sha1sum > out2) > out3
@pavlov99
Copy link
Member Author

pavlov99 commented Jul 4, 2020

This was implemented in 678e728 commit.

@pavlov99
Copy link
Member Author

pavlov99 commented Jul 4, 2020

Performance comparison: python implementation vs awk implementation.

Compare head of the file (common pretty printing case), 350 lines files and >1k lines file.

Python vesion

cat file | time -f '%es' .env/bin/python -c 'from tabtools.scripts import *; ttpretty()'

Awk version

cat file | time -f '%es' ./bin/ttpretty
File Python Code Awk Code
7 columns, 10 rows (head) 0.04s 0.01s
7 columns, 338 rows 0.05s 0.02s
14 columns, 10k rows 0.40s 0.72s

@pavlov99
Copy link
Member Author

pavlov99 commented Jul 5, 2020

After script rewriting, it outperforms python version:

File Python Code Awk Code
7 columns, 10 rows (head) 0.04s 0.01s
7 columns, 338 rows 0.05s 0.02s
14 columns, 10k rows 0.42s 0.38s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant