in reply to Re^2: opendir slower than ls on large dirs?
in thread opendir slower than ls on large dirs?
It's not that opendir is slow, it's calling readdir, building the list, passing that list through to grep, which starts the regex engine once for every file in the list, building the output list and assigning it to the array.
With large lists, much of that time would expanding memory to stages (powers of 2?) to accomodate the lists as they grow.
With glob, everything is done within the C code which is entered and exited once.
|
|---|