Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Array question

I have a macro that processes a text file, reading data one line at a time.

Originally I did 2 "passes" on the file, the first step merely established
the number of lines in the file so that I could use a progress indicator on
the next pass through the file where I did my actual processing.

Then I got the bright idea that instead of opening and closing the file
twice I only needed to do it once and could save considerable processing
time. I would open the file, and pass each line to an arrayed variable.
After establishing the mumber of lines I would then access the array data
instead of opening the file again.

To my surprise this ended up saving virtually no time at all. Can anyone
explain this ?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Array question

Perhaps reading a file is not as inefficient as you thought. If you are
filling the array fully, then reading the array, isn't this like reading the
file twice? I am curious how much time difference there is between just
reading the once vs reading it twice? For small files (< 100's of thousands
lines), I would expect the difference to be barely noticeable.

Bob

"Steve Farrar" wrote in message
ink.net...
I have a macro that processes a text file, reading data one line at a

time.

Originally I did 2 "passes" on the file, the first step merely established
the number of lines in the file so that I could use a progress indicator

on
the next pass through the file where I did my actual processing.

Then I got the bright idea that instead of opening and closing the file
twice I only needed to do it once and could save considerable processing
time. I would open the file, and pass each line to an arrayed variable.
After establishing the mumber of lines I would then access the array data
instead of opening the file again.

To my surprise this ended up saving virtually no time at all. Can anyone
explain this ?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Array question

Yes, in general, disk i/o is slower than memory access, but...

If the file is small enough and the system has enough memory, it could
be caching enough/all of the file...

Or, the file is so large and the array contains so much data that the
virtual memory manager is swapping parts of the array to the
swapdisk...

Or, the sequential read of the file triggers a sufficiently smart 'read
ahead' capability within the IO subsystem that records you access are
always in memory...

Or...

--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article . net,
says...
I have a macro that processes a text file, reading data one line at a time.

Originally I did 2 "passes" on the file, the first step merely established
the number of lines in the file so that I could use a progress indicator on
the next pass through the file where I did my actual processing.

Then I got the bright idea that instead of opening and closing the file
twice I only needed to do it once and could save considerable processing
time. I would open the file, and pass each line to an arrayed variable.
After establishing the mumber of lines I would then access the array data
instead of opening the file again.

To my surprise this ended up saving virtually no time at all. Can anyone
explain this ?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
array question Mona Excel Discussion (Misc queries) 2 March 23rd 10 08:41 PM
another array question Robert Dieckmann Excel Worksheet Functions 5 January 20th 07 02:08 AM
vba array question chick-racer[_30_] Excel Programming 4 November 10th 03 05:59 PM
array question john petty Excel Programming 1 August 29th 03 04:57 PM
Is this an array question? Stuart[_5_] Excel Programming 0 August 5th 03 08:53 PM


All times are GMT +1. The time now is 11:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"