Is calculating for Arrays faster then .txt files ?

• 12-25-2007
Coding
Is calculating for Arrays faster then .txt files ?
I wonder if calculations of arrays is faster compared to if you do calculations from a simple .txt file.
I will give this example.

(Calculation from a .txt file while reading it)
The .txtfile has one line and look like this:

1,2,3,4,5

I will do a calculation right from the file while reading. I split the values and do:
1*2*3*4*5 wich will give me: 120
.................................................. ..........................

Instead of the above approach I will already have these values stored and ready in an array called Test[4]
The calculation will be:
Test[0] * Test[1] * Test[2] * Test[3] * Test[4] wich will give me: 120

Now I wonder if the calculations with the arrays is faster than while reading from a .txt file in realtime and doing the calculations.
If it is, how much faster are we talking about here ?
We could also refer to an example where we will use 1 million numbers instead of 5 as in our example wich will be closer to what I will do later.

Why I wonder this is because I will use very large .txtfiles and do calculations with.
Thanks...
• 12-25-2007
The Brain
there are a lot of variables concerning arrays and text files to take into consideration, but i will attempt to give you my answer at the most general level. This is like comparing apples to oranges.

There is a lot more overhead using the ifstream and ofstream libraries as opposed to performing a basic array calculations.

Often, when a file is read, the text is stored into an array.

Calculations on an array of primitive data types is faster than an array of an aggregate data type. Example, array calculations on an array of int's is faster than array calculations on an array of structs or classes.

All of these answers are dependent on what type of calculations ye' want to do in the first place.
• 12-25-2007
cpjust
I'm not quite sure what you're trying to ask, but I'll take a shot in the dark at giving you some answers.

Reading from RAM is over 1000 times faster than reading from a hard disk.

You can't do any calculations using data on disk; you must load it into RAM, then the program will load it into cache and into CPU registers... So if your data is in a .txt file, load it into some variables once and use those variables for all your calculations (don't re-read the same .txt file over and over again).
• 12-26-2007
Elysia
But it's much more efficient to read all data at once rather than nibble a little data at a time and do the calculations. So read all the data into an array and process it from there.
If you don't have to read at all, you'll see huge improvements as well.
• 12-26-2007
Coding
Yes thats what I thougt also, I will try to read in all data into arrays once and from here I will do all the calculations.
This sounds like a good solution..