coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

head: performance is pretty bad for non-seekable files

Open karlmcdowall opened this issue 11 months ago • 1 comments

On my laptop, I get the following results when running benchmarks for non-seekable files...

hyperfine  "cat shakespeare.txt | head -n -100000"     "cat shakespeare.txt | ./target/release/head -n -100000"

Summary
  cat shakespeare.txt | head -n -100000 ran
   16.03 ± 1.60 times faster than cat shakespeare.txt | ./target/release/head -n -100000



hyperfine  "cat shakespeare.txt | head -c -100000"     "cat shakespeare.txt | ./target/release/head -c -100000"

Summary
  cat shakespeare.txt | head -c -100000 ran
   18.56 ± 1.61 times faster than cat shakespeare.txt | ./target/release/head -c -100000

So the current Rust implementation is a lot slower than GNU for non-seekable files.

I have some changes drafted to resolve this and they seem to be work well. I need to tidy up the code and then I'll post with updated benchmarking results.

karlmcdowall avatar Mar 01 '25 18:03 karlmcdowall

Changes for this are done here

karlmcdowall avatar Mar 17 '25 16:03 karlmcdowall

Fixed here

karlmcdowall avatar Apr 19 '25 16:04 karlmcdowall