473,408 Members | 1,601 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Anything faster than stat() ?

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
Jul 19 '05 #1
1 3018
Ken Tucker <ke*@nospam.iit.net> 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
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Fred Pacquier | last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been able to phrase my questions well enough to get a meaningful answer from Google in my research. OTOH, it is standard...
8
by: fuzzylollipop | last post by:
I am trying to get the number of bytes used by files in a directory. I am using a large directory ( lots of stuff checked out of multiple large cvs repositories ) and there is lots of wasted time...
3
by: Steven T. Hatton | last post by:
I found the following two statements in the file linked below: struct stat st; stat(fileName.c_str(), &st); http://websvn.kde.org/branches/work/kdevelop4-parser/main.cpp?rev=420247&view=markup...
10
by: David Farning | last post by:
I am new to c and not yet sure of the boundary between c and it's implementations. So please redirect me if this should be asked elsewhere. I am working on a function to determine if a directory...
5
by: diadia | last post by:
#include <sys/types.h> #include <sys/stat.h> #include "ctype.h" #include <stdio.h> int estimateLen(struct stat buf, FILE *fp) { size_t _size = buf.st_size / 4;
3
by: David Bear | last post by:
I'm trying to use os.chmod and am refered to the stat module. Is there are explanation of: * S_ISUID * S_ISGID * S_ENFMT * S_ISVTX * S_IREAD * S_IWRITE * S_IEXEC
2
by: Michael Glassford | last post by:
The Python 2.5 News at http://www.python.org/download/releases/2.5/NEWS.txt states that Python 2.5 was changed to "Use Win32 API to implement os.stat/fstat. As a result, subsecond timestamps are...
24
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several...
3
by: Deniz Dogan | last post by:
Hello. I have a question regarding the st_mode field of the "stat" struct in sys/stat.h. I'd like to know how to use the S_IRWXU, S_IRWXG and S_IRWXO flags to mask the mode_t value into human...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.