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



tom fredriksen wrote:
Hi

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)

HTH,
AvK
.



Relevant Pages

  • Re: removing a loop cause it to go at half the speed?
    ... 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 ...
    (comp.lang.c)
  • Re: removing a loop cause it to go at half the speed?
    ... tested it I found that removing the loop that initialises the data array ... If the loop is included it takes about 7.48 seconds to ... Perhaps the array needs to be swapped in on the ...
    (comp.lang.c)
  • removing a loop cause it to go at half the speed?
    ... 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. ... int main ...
    (comp.lang.c)
  • Re: removing a loop cause it to go at half the speed?
    ... 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 ...
    (comp.lang.c)
  • Re: CISC architecture today
    ... i-cache miss rate, but that even for these, the effect of architecture ... A loop that almost-but0-not-quite-fits can show dramatic gains from a marginal increase in effective cache. ... While every bit helps, the return from adding more cache, reducing internal fragmentation and improving program entropy is gradual, not the step function seen by loop-bound code. ...
    (comp.arch)