R
Robert Mischke
I'm writing a backup program that needs to check a lot of file sizes
and timestamps. Reading the directory tree itself is reasonably fast:
about 4 seconds for a test tree with 4.000 directories and about
40.000 files.
But when I add code to read the timestamps of the files, it gets
extremely slow: from 4 seconds without to 28 (!) seconds with calling
File.lastModified once per file. The actual class that gets
constructed from each found File object looks like this:
public class SingleFile
{
public String filename;
public long timestamp;
public long size;
public SingleFile(File fileObject)
{
// with this line alone, scanning takes 4 seconds
filename = fileObject.getName().intern();
// the critical line which adds about 24 seconds:
timestamp = fileObject.lastModified();
// this line adds another 2 seconds (30 sec. total)
size = fileObject.length();
}
//...
}
I made sure that each File object passed to the constructor is
actually a file, not a directory. I'm using the Sun SDK 1.4.2_03
virtual machine.
Has anyone encountered this before? A web search turned up nothing;
any hints and ideas are much appreciated.
Thanks,
Robert
and timestamps. Reading the directory tree itself is reasonably fast:
about 4 seconds for a test tree with 4.000 directories and about
40.000 files.
But when I add code to read the timestamps of the files, it gets
extremely slow: from 4 seconds without to 28 (!) seconds with calling
File.lastModified once per file. The actual class that gets
constructed from each found File object looks like this:
public class SingleFile
{
public String filename;
public long timestamp;
public long size;
public SingleFile(File fileObject)
{
// with this line alone, scanning takes 4 seconds
filename = fileObject.getName().intern();
// the critical line which adds about 24 seconds:
timestamp = fileObject.lastModified();
// this line adds another 2 seconds (30 sec. total)
size = fileObject.length();
}
//...
}
I made sure that each File object passed to the constructor is
actually a file, not a directory. I'm using the Sun SDK 1.4.2_03
virtual machine.
Has anyone encountered this before? A web search turned up nothing;
any hints and ideas are much appreciated.
Thanks,
Robert