-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Reading file from disk redirected to stdin
is faster than directly from disk
#99458
Comments
When using Something like this should do it: - xor_hasher(std::fs::File::open(&p_a)?.bytes(), sbox)
+ xor_hasher(std::io::BufReader::new(std::fs::File::open(&p_a)?).bytes(), sbox) |
@Urgau Thank you so much! I got these timings now:
But I was wondering, what's the rationale behind the file byte iterator not using a |
Suggested by: rust-lang/rust#99458 (comment) Fixes (partially) #16
This has nothing to do with the As for the actual reason for why |
It is. The stdio handles provide thread-safety (e.g. incrementally writing out messages without line-tearing) by wrapping the raw IO in a mutex. And since it already is higher-level it also provides buffering on top. #78515 aims to make stdout buffering switchable. |
Thank you all for the info, I think the issue can be closed for now. If there's any reason to keep it open, please let me know |
I'm using the byte iterator to get the bytes from a file, and it seems this post is still relevant.
This is my benchmark code:
Direct:
Out:
Redirect:
Out:
xorsum
is the crate I'm developing. The code I benched is not exactly the same as the one in my repo (Currently. I'll commit my local clone in some minutes after doing some minor changes)And yes, I ran
cargo build -r
to optimize it. Memory-mapping and file-caching shouldn't affect bench results, because I always used random dataUpdate: permalink to the commit
The text was updated successfully, but these errors were encountered: