Hey John, On Sat, Jan 15, 2022 at 3:04 AM Jon Smart <j...@smartown.nl> wrote:
> > Hello Paul > > Do you mean by undef $/ and with <$fh> we can read the file into memory > at one time? > In most cases the short answer is yes. I have problems with your wording however given the 'geek' that I am. 'At one time' .... not quite. In your example there were over 4000 read(2) syscalls by the operating system for instance. This wouldn't have been 'at one time'. ;) Yes that would be faster b/c we don't need to read file by each line, > which increases the disk IO. > > It actually doesn't make it faster. Perl buffers it's reads as does all modern programming languages. If you ask perl to give you 10 bytes it certainly will, but what you don't know is that perl has really read up to 8192 bytes. It only gave you what you asked for and the rest is sitting in perl buffers. To put this another way, you can put 8192 newline characters in a file and read this file line by line. This doesn't equate to 8192 separate read(2) syscalls ... it's just 1 read syscall. It won't be faster nor slower. > Another questions: > 1. what's the "truss" command? > truss is akin to strace. If you're on linux, you can install strace and get the samish type of utility. It allows you to trace system calls and see how much of your time for a given program is waiting on the kernel and/or how often it's asking the kernel to do something. 2. what's the syntax "<:mmap"? > > mmap is a method of mapping a file (among other things) into memory on an on-demand basis. Given the example you provided, this is actually where the speed up comes from. This is because my version removes the 4000+ read(2) syscalls in favor of just 2 mmap(2) syscalls. Thank you. ~Paul