I have rewritten a computation library to improve memory management and have discovered that this has resulted in a speed increase. In the original it uses an array whose members are 12 doubles (so 96 bytes) apart in memory, whereas my array is contiguous.
How much of a speed increase would this difference provide?
I have created a small test program that calculates the array element access times for 1D and 2D arrays. It is a
Consoleapplication in C# .NET built inReleasemode (with optimizations enabled). If the size of the 1D array ismthen the size of the 2D array ism x m.The results on my machine (2.8 GHz Phenom II quad core, 8 GB DDR2 800 MHz RAM, Windows 7 Ultimate x64) are
Interestingly, the results are quite clear, the access times for 2D array elements is significantly greater than those for 1D array elements.
Determining whether time taken is a function of array size
1002012(your use case)As you can see, the array size does make a difference in the element access time. But, in your use case of array size as
12, the difference is about (0.0016548 msfor 1D vs0.0020762 msfor 2D)25% i.e. 1D access is 25% faster than 2D access.When the lower array size is smaller in case of 2D array
In the above samples, if the size of the 1D array is
mthen the size of the 2D array ism x m. When the size of the 2D array is reduced tom x 2, I get the following results form = 12In this case, the difference is hardly 1.3%.
To gauge the performance in your system, I would suggest that you convert the above code in FORTRAN and run the benchmarks with actual values.