find . -maxdepth 1 -mindepth 1
Those arguments will remove the need for find to stat each directory entry. Regardless, this is a nice walk through of low level details often overlooked. find . -maxdepth 1 -mindepth 1
Those arguments will remove the need for find to stat each directory entry. Regardless, this is a nice walk through of low level details often overlooked. open(".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5
fcntl(5, F_GETFD) = 0x1 (flags FD_CLOEXEC)
fchdir(5) = 0
getdents(5, /* 2 entries */, 32768) = 48
getdents(5, /* 0 entries */, 32768) = 0
close(5) = 0
It's only reading 32k at a time, but the author had 500MB of data to be fetched.Many of the standard-tools that most people would intuitively expect to be rather optimized (find, rsync, gzip) are embarrassingly inefficient under the hood and turn belly up when confronted with data of any significant size.
That probably stems from the fact that most of the development on these tools took place during a time when 1GB harddrives were "huge" and SMP was "high end".
Maybe because listing 8M files is not a common use case, and there just isn't the motivation to update otherwise perfectly working code. It's not an itchy problem.
Certainly find . would have been faster without calling stat().
Does os.listdir() stat?
Often, when ls is being slow, you can speed things up drastically by disabling the things that require a stat (colors, -F, etc.) that are often added by distro's shell files (invoking ls with a full path is an easy way to disable shell aliases.) Also, sorting is on by default, which slows things for obvious reasons.
When all you need to do is kill the stat overhead for small dirs on slow file systems, "echo *" is beautifully simple.
> invoking ls with a full path is an easy way to
> disable shell aliases
Or doing this: > 'ls'\ls -f
env ls
Notes:* IIRC 'env' is a built-in on csh/tcsh though, and doesn't behave like I would expect it to. You may want to read that manpage in that case.
* This is how the following works:
#!/usr/bin/env python