Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: opendir slower than ls on large dirs?

by neniro (Priest)
on Jul 05, 2005 at 09:48 UTC ( #472399=note: print w/replies, xml ) Need Help??

in reply to opendir slower than ls on large dirs?

In case of foo() you just slurp the output of ls into a single variable, in both other cases you get arrays as result. You compare apples to pears.
  • Comment on Re: opendir slower than ls on large dirs?

Replies are listed 'Best First'.
Re^2: opendir slower than ls on large dirs?
by Anonymous Monk on Jul 05, 2005 at 10:06 UTC
    switching @files for $files doesn't change speed.

    Also, opendir with or without pre-open is 6-10 times quicker on a small dir but twice as slow on a large dir.

      Er, no because an intermediate list is still being built. I think the fairer comparison would be to assign to an array in the foo subroutine.

      Of course a readdir and a grep is not at all equivalent to ls <file> which will immediately see that $file exists (or not) and will not do any further searching, in the pure perl code you are going through every directory entry irrespective of whether you have seen the file or not. You will see somewhat similar performance hit if you did `ls $dir | grep $file`


        Well ok, it's not the exact thing but my original point was more "how the hell can it be so damn slow". When you look at perldoc -f readdir the grep sollution is what's suggested, eventhough it seems like a really bad idea.

        A little mention of glob would be nice as it does the exact same thing but a hundred times quicker or so.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://472399]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2023-01-29 19:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found