total() vs. rebin() speed for 1D averaging or integration [message #85426] |
Thu, 01 August 2013 21:06 |
kagoldberg
Messages: 26 Registered: November 2012
|
Junior Member |
|
|
In hopes that this could be useful for anyone trying to optimize calculation speeds, I've noticed that there can be big a difference between two ways of performing a one-direction averaging or 1D integration on a 2D array.
a = randomn(seed, 200, 2048)
a1 = total(a, 2) ;--- this performs a column total
a2 = rebin(a, 200, 1) ;--- this returns a column average
Trying a few different values for the array size, I see that for single-precision floating-point, there can be a 3x speed improvement with rebin as the winner. When the array size gets to be large (2048x2048), or when the array is a double-precision floating-point, then it's nearly a tie on my machine.
In any case, it's worth running a test, if you're choosing one over the other and you care about speed. YMMV.
|
|
|