Anything faster than stat() ?

Discussion in 'Perl' started by Ken Tucker, Jul 7, 2003.

  1. Ken Tucker

    Ken Tucker Guest

    Help!

    I'm recursing through 10,000 directories where some have as few as 5 files
    and others have 100's. I'm then performing a few things based on the modify
    date of the file. Needless to say, this script is going to run a long time
    regardless of what I do. But if I remove the stat, the script runs 500%
    faster (duh). That being said, I've set out to find something faster than
    stat if at all possible (since stat gets much more info than I need).

    I've noted that doing a file check (-f) slows down execution significantly
    so I've removed it in favor of regular expressions, but I can't find another
    way to get the modify date of each file other than stat and -M.

    Anyone have any other ideas? I'm running this in Win32, so I'm sure that's
    part of the cause, but perhaps there's a stat-like command that ONLY grabs
    modify date, or perhaps there's something in a Win32 module that I haven't
    found.

    Here's a snippet of code in case it helps.

    # open the current directory
    opendir D, "$checkpath";

    # loop through files in directory
    while (defined($file = readdir D)) {
    chomp($file);
    # if there's a . in the file, it must be real (weak but works for
    now)
    if ($file=~ /\./) {
    # get the time, in seconds, of the file since Jan 1 1970
    $filetime = int((stat($file))[9]); <--- SLOW!

    # do something with it...
    }
    }

    Thanks in advance!
    -Ken
    Ken Tucker, Jul 7, 2003
    #1
    1. Advertising

  2. Ken Tucker <> wrote:
    > Forget stat(). I just used regular expressions to parse through
    > a DOS directory listing ... it went from 256 seconds to 16 seconds


    That will be specific to Windows.

    > So - word to the wise -


    [ insert joke here ]

    --
    Steve
    Steve Grazzini, Jul 8, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven T. Hatton
    Replies:
    3
    Views:
    9,696
    Pete Becker
    Jun 2, 2005
  2. Patrick Useldinger

    os.stat('<filename>')[stat.ST_INO] on Windows

    Patrick Useldinger, Feb 27, 2005, in forum: Python
    Replies:
    6
    Views:
    1,159
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Mar 3, 2005
  3. Magesh
    Replies:
    3
    Views:
    434
    Gordon Burditt
    Oct 5, 2007
  4. Rolf Krüger
    Replies:
    2
    Views:
    607
    Ian Collins
    Mar 12, 2008
  5. ruck
    Replies:
    10
    Views:
    1,263
Loading...

Share This Page