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

Re^2: opendir slower than ls on large dirs?

by Anonymous Monk
on Jul 05, 2005 at 10:06 UTC ( [id://472400]=note: print w/replies, xml ) Need Help??


in reply to Re: opendir slower than ls on large dirs?
in thread opendir slower than ls on large dirs?

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.

Replies are listed 'Best First'.
Re^3: opendir slower than ls on large dirs?
by gellyfish (Monsignor) on Jul 05, 2005 at 10:28 UTC

    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`

    /J\

      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found