May 24, 2013

FileSystemObject performance issues

By Mike Lewis

In a recent Hex Central article, I explained how you can use the FileSystemObject to read and write large text files in Visual FoxPro. One of the main reasons for doing that is to work with files that would otherwise break VFP's 2 GB limit.

Unfortunately, that benefit comes at a price. In many cases, the FileSystemObject will be a lot slower than using native VFP commands and functions.

In my tests, I found that using the FileSystemObject typically took five to seven times as long to read and write files as VFP's low-level file functions (such as FOPEN() and FREAD()). It also took longer to import a text file into a table, compared to using VFP's APPEND FROM … DELIMITED command.

I ran these tests on a 75 MB file, containing about one million lines of text. In summary, the results were as follows (all times in seconds):

Write file24.14.9
Read file13.71.9
Import text file125.287.7

So the message is clear. If your files are below the 2 GB limit, always favor native VFP commands and functions over the FileSystemObject. If your files are larger than that figure, you'll have to put up with the FileSystemObject's relatively poor performance.

No comments:

Post a Comment