Re: Optimization of array access

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Christoph,

> Why is simulating an 3d-array by pointers faster than using a contingous
> memory array?

test_pointer does not run faster on my machine.

Array1: 0.146805 s
Array2: 0.148514 s
Zeiger: 0.198865 s
Array3: 0.146694 s
Arr3D : 0.147899 s

Array1 is the test_array as you provided.

Array2 is the test_array in the commented out part.

Zeiger is the test_pointer as you provided.

Array3 is my own variant of test_array seeing if I could do some hand loop
unrolling.  No significant performance gain.

Arr3D is using an: int array3d[SIZE][SIZE][SIZE] = { };, which otherwise
looks a lot like test_pointer.

Also...

Your test neglected to do...
1) call gettimeofday() a couple times before trusting it
2) pre-run each test once just before timing it, to make the cache hot
3) or alternatively, set a memory barrier to clear the cache to make it cold

Not doing those things can skew your results.  I used both #1 and #2.

Sincerely,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux