Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Slurping a file (was: more spllitting travails)



On Sun, Jan 14, 2024 at 11:34 AM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> I've benchmarked read and slurp for reading files and pipes.
>
> [...]
>
> Observations from the data:
>
> - All routines appear to have linear time complexity.
> - For small files, read is up to twice as fast as slurp.
> - For files over 256 bytes in size, slurp is faster.
> - With slurp, the time it takes to read from a pipe is about 2x
>   compared to reading from a file. With read, the penalty is 8x.
> - For an 8MB file, slurp is 20 times faster than read when reading
>   from a file, and 70 times faster when reading from a pipe.

I've also benchmarked mapfile. As expected, it is the fastest method
of reading a file. For small files, slurp is up to 5 times slower, but
for larger files the difference is rather small: for a 64kB file slurp
is only 25% slower.

Roman.




Messages sorted by: Reverse Date, Date, Thread, Author