Re: removing a loop cause it to go at half the speed?

tom fredriksen wrote:

I was doing a simple test of the speed of a "maths" operation and when I tested it I found that removing the loop that initialises the data array for the operation caused the whole program to spend twice the time to complete. If the loop is included it takes about 7.48 seconds to complete, but when removed it takes about 11.48 seconds.

Does anybody have a suggestion as to why this is so and whether I can trust the results of the code as it is below?

My guess would be: your initialisation fills the memory cache.
(all your data will probably fit into the L2 cache)
Without the initialisation, 1/4 (?) of the array-accesses will result in a cache miss, and the processor will have to wait for the bus to grab the data from RAM. (you could increase the arraysize to test this hypothesis)