in reply to Re: Finding files recursively
in thread Finding files recursively

Thanks for your suggestion but I don't understand the difference between both suggestions. Also, what is $target?. Thank you again.

Replies are listed 'Best First'.
Re^3: Finding files recursively
by holli (Abbot) on Aug 04, 2019 at 20:20 UTC
    $target is just the filename you are looking for, "secret.file" in your case.
    The difference is that my code is exiting the wanted function immedeatly when it is not dealing with a directory. Only if there is a directory it is looking wether the target file is in that directory.

    Whereas your code looks at each and every file, calculates its' base path (albeit unneccessary, that info is already there in $File::Find::name). And then it takes that base directory to look for the target file.
    This, and this is the biggest slowdown, also means that you are testing the same directory number-of-entries-in-the-directory times.


    holli

    You can lead your users to water, but alas, you cannot drown them.
      Back with results! :)
      I tried my code and your code. My code ran for 13858 seconds and your code ran for 16968 seconds. I thought it will reduce the time a little but it didn't, maybe because the machine was being used by others at that time but it is a big difference. Do you have any other suggestions? 4 hours for searching is quite a lot of time :(
        You should probably test on a smaller data set then? Anyway, I'm getting different results, my original code being roughly 55% faster on my single user machine (as expected).

        I added a native Perl implementation that walks the tree itself with no overhead and that gains you another significant speed boost.
        D:\ENV>perl pm10.pl Holli (New). Found: 1 ( D:\env\Videos/2012 ) Time: -19 Holli (original). Found: 1 ( d:\env/Videos/2012 ) Time: -32 ovedpo15. Found: 1 ( d:/env/Videos/2012 ) Time: -51
        Using this code.


        holli

        You can lead your users to water, but alas, you cannot drown them.