ineffecient to access arrays out of sequence
basically little observation made when accessing arrays out of sequence.
i had inside isr, , affected performance worse. found pretty strange code little bit of isr. tried have array element 2 @ top (not important @ of course).
putting in sequence made faster again. thought wouldn't matter, guess compiler optimizations when arrays accessed in sequence?
i have since optimized isr ~40% latency, these 2 versions (array in sequence vs out-of-sequence), had latency of 53 timer2 clock cycles (86% latency) , (seemingly) 56 clock cycles (should have been 89%, although program reported 94% think was, not sure why). pretty @ limit of missing isr while inside isr timer2 timeout of 63 clock cycles (every 1 ms, or 1000 hz, timer load value of 193 (=256-63)).
however last figure of 56 clock cycles wrapped around several times. timing 1000 loops of main loop took 9 seconds array in sequence, while other took 1 min. 18 seconds. had real big performance hit, more i'd think difference of 14% execution time main loop vs. 11% (or 4%).
at least get. followed excellent tutorial on arduino timer interrupts btw: http://www.uchobby.com/index.php/2007/11/24/arduino-interrupts/ in case others interested.
i had inside isr, , affected performance worse. found pretty strange code little bit of isr. tried have array element 2 @ top (not important @ of course).
code: [select]
for ( int x=0 ; x<4 ; x++ )
{
for ( int y=0 ; y<4 ; y++ )
{
int cx = x+1;
int cy = y+1;
int fivecy = 4 - y; // 5-cy
face[2][x][y] = cube[cx][fivecy][0]; // top (face 2)
face[0][x][y] = cube[5][cx][cy];
face[1][x][y] = cube[cx][0][cy];
face[3][x][y] = cube[0][cx][fivecy];
face[4][x][y] = cube[fivecy][5][5-cx];
face[5][x][y] = cube[cx][cy][5]; // bottom (face 5)
}
}
putting in sequence made faster again. thought wouldn't matter, guess compiler optimizations when arrays accessed in sequence?
i have since optimized isr ~40% latency, these 2 versions (array in sequence vs out-of-sequence), had latency of 53 timer2 clock cycles (86% latency) , (seemingly) 56 clock cycles (should have been 89%, although program reported 94% think was, not sure why). pretty @ limit of missing isr while inside isr timer2 timeout of 63 clock cycles (every 1 ms, or 1000 hz, timer load value of 193 (=256-63)).
however last figure of 56 clock cycles wrapped around several times. timing 1000 loops of main loop took 9 seconds array in sequence, while other took 1 min. 18 seconds. had real big performance hit, more i'd think difference of 14% execution time main loop vs. 11% (or 4%).
at least get. followed excellent tutorial on arduino timer interrupts btw: http://www.uchobby.com/index.php/2007/11/24/arduino-interrupts/ in case others interested.
quote
i thought wouldn't matter, guess compiler optimizations when arrays accessed in sequence?
well, guess 3-d array plane/row calculations involve multiplication if accesses out of numerical order, in-order allow compiler optimise , use simple additions of constants.
but that's guess.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > ineffecient to access arrays out of sequence
arduino
Comments
Post a Comment