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: Optionally write to a buffer instead of stdout #2618

Merged
merged 6 commits into from
Sep 1, 2023

Conversation

Piturnah
Copy link
Contributor

@Piturnah Piturnah commented Jul 9, 2023

Following on from my comment in #956, this PR adds the ability to write output to a std::fmt buffer instead of stdout. It does this by changing the handle used by the printer to be a mutable reference to either one of dyn fmt::Write or dyn io::Write.

Included is also an added example to show that it works. I didn't add it to the PrettyPrinter but I can do if it seems like a good idea.

Anything else let me know!

@sharkdp
Copy link
Owner

sharkdp commented Sep 1, 2023

Can we please run a simple benchmark (e.g. bat large-plaintext-file.txt) to make sure this doesn't lead to any regression.

@Piturnah
Copy link
Contributor Author

Piturnah commented Sep 1, 2023

Command Mean [ms] Min [ms] Max [ms] Relative
bat-main 797.0 ± 6.1 790.5 817.9 1.01 ± 0.01
bat-2618 792.9 ± 2.6 788.7 800.6 1.00

Both compiled in release mode, bat-main comes from 8676bbf (the commit this PR is based on)

5 warmup runs, 20 runs

Command used to generate the file:
tr -dc "A-Za-z 0-9" < /dev/urandom | fold -w100|head -n 1000000 > large-plaintext-file.txt

@sharkdp
Copy link
Owner

sharkdp commented Sep 1, 2023

Thank you very much!

tr -dc "A-Za-z 0-9" < /dev/urandom | fold -w100|head -n 1000000 > large-plaintext-file.txt

❤️

@sharkdp
Copy link
Owner

sharkdp commented Sep 1, 2023

I'm just rebasing to current master to see if the tests still pass.

@sharkdp sharkdp merged commit b06f13f into sharkdp:master Sep 1, 2023
21 checks passed
@Piturnah Piturnah deleted the feat/write-to-buffer branch September 1, 2023 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants