Re: Need help with efficiency NXC code
Posted: 13 Aug 2011, 23:20
So how else can I speed it up?
Give a child a robot, he'll play for an hour. Teach him to build, and he'll play forever.
https://mindboards.org:443/
Did you do the local precaching of arrays where possible and the re-ordering of logical expressions? How much faster did your program run?nxtboyiii wrote:So how else can I speed it up?
I often had speed issues by my own, and I experienced the following (as partially Linusa said before):nxtboyiii wrote:So how else can I speed it up?
Code: Select all
map_struct map[ width * height ];
map_struct temp = map[ x + y*width ]; //returns map[x][y]
Code: Select all
map_struct map[ width * height ];
unsigned int xy_pos = E.mex + E.mey * width;
map_struct temp = map[ xy_pos ]; //returns map[x][y]
temp = map[ xy_pos + 1 ]; //returns map[x+1][y]
temp = map[ xy_pos + width ]; //returns map[x][y+1]
Code: Select all
map_struct temp = map[x][y];
temp.sld = 0;
map[x][y] = temp;
That's completely wrong.doc-helmut wrote:Your eyes are not able to recognize changes faster than 25 times per second anyway because of inertia .
As your link said: Always a trade-off. It doesn't say "don't unroll". What I'd like to know is how the concept of "instruction cache" and alignment and all that is used on the NXT's CPU, and how it's managed by the firmware (with the "code clumps" and all that). But I'm not a hardware/low-level guy, so it's not my field anyway.muntoo wrote: Oh, and don't unroll your loops - it may actually make your program slower as well as make it larger! (Reference.)
I meant "unrolling loops" only if you can reduce counters (for constants instead), but anyway: your reference was not especially for NXC...muntoo wrote:
Oh, and don't unroll your loops - it may actually make your program slower as well as make it larger! (Reference.)