Re: [dev] Re: coreutils / moreutils - DC a directory counter

From: Troels Henriksen <athas_AT_sigkill.dk>
Date: Thu, 18 Jul 2013 12:30:23 +0200

Bjartur Thorlacius <svartman95_AT_gmail.com> writes:

> On 07/17/2013 09:02 PM, Calvin Morrison wrote:
>> So it seems a good deal of that time is ls
>>
> Wait, sbase ls doesn't seem to implement -f. Are you sorting the
> directory entries?

Using -f improves performance a bit, but no matter what, an 'ls
-whatever|wc -l' pipeline is going to be slower than a dedicated tool.
Consider that counting the number of files in a directory using the
system call interface requires about a single system call per file (plus
a few to open the directory etc), where piping the file names to another
program vastly increases the number of system calls. Furthermore, 'wc
-l' has to scan the entire byte stream looking for newline characters,
which doesn't require system calls (apart from reading the pipe), but
still takes time. Since the ls and the wc can run in parallel, I
suspect that the major overhead is the additional system calls in ls (or
the sorting, if not disabled).

-- 
\  Troels
/\ Henriksen
Received on Thu Jul 18 2013 - 12:30:23 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 18 2013 - 12:36:05 CEST