123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|403|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> Discussion point: read one long line or multiple short lines?

Fri, 23 May 2008, 11:38
Forklift_Fred
This is a question that doesn't really need an answer as the implementation I'm looking for is minimal and decided on by other factors, but I wondered what everyone thought of the matter...

It's also one that can be tested and so on, but I can't be bothered

I'm writing a very simple little application for work, like one I've mentioned before. I basically need to read in less than 20 pieces of text (stored in a TXT or CSV so it can be easily edited at a later date) and shove them into a collection of Types.

My question then...

Is it quicker to read one line from a file then parse it with comma separations or have each string on one line and read 20 lines from the file?

I'm thinking, for ease of editing, I'll save it as a CSV and read multiple lines. That way it can be sorted and entries can be deleted quickly and easily in Excel (which is in common use by the manager who is likely to edit it)

I'd started with a single line because I'd just been working with comma separation and I thought one read would be quicker but it's getting messy with different string lengths:



My algorithm isn't quite right anyway so I have to re-code.

So... a lot of waffle for a simple question! What are your thoughts?

Discuss...

-=-=-
Come rain or shine...
Fri, 23 May 2008, 12:01
Andy_A
Reading the entire line of text from a disk file into a single string is definitely going to be faster. Then just parse the line for the different fields and store the values in an array for sorting/searching.

This might do what you want

https://socoder.net/index.php?snippet=13836
Fri, 23 May 2008, 12:24
JL235
If you can guarantee the structure, then I'd read one line at a time. I also wouldn't worry about performance until after it's done.

But personally I would do neither. I'd just read and read turning the input into tokens. Some example tokens: WHITESPACE, TEXT, COMMA, END_OF_LINE and NUMBER. The idea being that what you do next is based on the tokens you've just received. Some like TEXT and NUMBER would also store their number and text inside. This token idea is how a lot of parsers work.
Fri, 23 May 2008, 12:26
Forklift_Fred
What Andy said is basically what I'm doing and it's all over in a matter of seconds anyway. It probably takes longer to open up the executable than it takes to run the code but it saves a couple of minutes from doing it manually

The idea is to read in a much larger CSV report (Currently about 600 lines - 54kb!) and ignore any lines that contain my listed entries. So ultimately, there's going to be about 600 ReadLine anyway a few WriteLine (in theory it would be zero but the point of the report is to find the problems and the examples I'm working with end up with about 25 lines)

I'm now wondering whether the 600 line report could be read as a single chunk of data and then converted and checked (or just checked as raw data???

-=-=-
Come rain or shine...
Sat, 24 May 2008, 16:45
Afr0
there's going to be about 600 ReadLine anyway


Please don't say you're going to hardcode 600 string variables into your program - right?

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 24 May 2008, 18:47
Forklift_Fred
No!

Only the 20 or so in my list get stored, the 600 are read, processed and forgotten. Nothing's hardcoded anyway, that's the whole point.

-=-=-
Come rain or shine...
Sun, 25 May 2008, 09:14
Afr0
Ah, good.
As for reading a single chunk of data... that should be entirely possible!
Just create a memorybank (or databank, or whatever it's called in Blitz), and poke it all in to there. Then you peek in a loop and use string commands to check it.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!