09-30-2008 03:16 AM
09-30-2008 03:23 AM
altenbach wrote:(Your program is way too complicated. 🙂 It is very expensive to read a file line-by-line
Could you please enlighten me on this like How is it expensive if i read a file line by line ?
N how will it Help if i read the whole file in a String and then process the string to get the desired output?
Thanks,
Ritesh
09-30-2008 03:35 AM
ritesh024 wrote:LabVIEW load error code 10: VI version(5.1) is too old to covert to the current LabVIEW version(8.5).
My code parse3.vi in in LabVIEW 8.5.1. There is nothing even remotely resembling 5.1 so I don't know what's wrong. Clear your browser cache and try downloading it once more. Maybe you got a corrupt download.
Just in case, I have downconverted the new version (parse4.vi) it to 8.2, so try this one. (I added the transposition and reading of the file. I have slighly modified the input data file and removed the last zero at the end (also attached). the lone zero at the end interfers with my algorithm)
09-30-2008 03:50 AM - edited 09-30-2008 03:52 AM
ritesh024 wrote:Could you please enlighten me on this like How is it expensive if i read a file line by line ?
N how will it Help if i read the whole file in a String and then process the string to get the desired output?
Reading from the HD is much more expensive than reading from memory. You do a new file IO operation for each line, but since the lenght of a line is variable, the program needs to read form the current position character by character until if finds a newline before it can know where the line ends and how much to read. Of course smart algorithms and disk caching improve these operations, but they are still much less efficient. Remember a file is just one long string of characters! There is no structure and the concept of a "line" does not exist per se, it is just the occurence of certain characters (\n, \r) scattered among other characters.
In my version, there is one single file IO operation and we know exactly how many characters to read (from the file size!) so all can be done very efficiently.
09-30-2008 07:12 AM
09-30-2008 07:16 AM
ritesh024 wrote:Could you please enlighten me on this like How is it expensive if i read a file line by line ?
N how will it Help if i read the whole file in a String and then process the string to get the desired output?
Which of the two will accomplish the task first? Person 1 or Person 2? The answer is obvious.
R
09-30-2008 07:18 AM
Just saw your reply. Altenbach is our resident expert at optimizing code 😉
Was hoping to write my little story faster... LOL! It kinda describes the difference in non technical terms. Plus I enjoy cooking 😉
LOL! 😄
09-30-2008 10:47 AM
Here's another analogy:
Problem: You need to mail a 500 page report to the branch office.
What solution is more efficient? 😄
09-30-2008 11:58 AM - edited 09-30-2008 11:59 AM
The 2nd solution..
Because by walking 500 times to the post office, you will get in better shape and start jogging instead of walking. Furthermore, by buying 500 stamps, you help the economy, although environmentalists will hate the fact that you used 500 enveloppes, so just don't tell them.
😉
there was more, but I thought it would be better to keep it short...
09-30-2008 01:05 PM
Suddenly, all this reminds me of stories such as this:
The Bank that was sent Through the Post office
So, yes, under certain situations, even this can be a valid approach considering all factors. 🙂