This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization of array access
- From: John Love-Jensen <eljay at adobe dot com>
- To: Christoph Bartoschek <bartoschek at gmx dot de>, GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 25 Apr 2008 09:12:09 -0500
- Subject: Re: Optimization of array access
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