I've pasted below a function from a program I'm working on. I can post full code if it helps. I've been trying to speed it up and found an odd thing.
Why is it quicker for this to step the innermost loop by two and do two comparisons than the the more obvious loop through one by one and do a single comparison? (it's also quicker than doing 3 at a time).
And if anyone can suggest a way to speed this up at all, please do.
Why is it quicker for this to step the innermost loop by two and do two comparisons than the the more obvious loop through one by one and do a single comparison? (it's also quicker than doing 3 at a time).
And if anyone can suggest a way to speed this up at all, please do.
Code:
THREAD FUNCTION MyThread (BYVAL dummy AS LONG) AS LONG REGISTER g& REGISTER h& DIM nptr AS LONG POINTER nptr=VARPTR(n(0,0)) tst&=0 dlt&=0 FOR z&=161 TO 1 STEP -2 ' sc&=0 FOR a&=44 TO 1 STEP -1 FOR b&=45 TO a&+1 STEP -1 FOR c&=46 TO b&+1 STEP -1 FOR d&=47 TO c&+1 STEP -1 FOR e&=48 TO d&+1 STEP -1 FOR f&=49 TO e&+1 STEP -1 FOR g&=162 TO 2 STEP -2 IF g&<>z& AND @nptr[g& OF 162,a& OF 49][email protected][g& OF 162,b& OF 49][email protected][g& OF 162,c& OF 49][email protected][g& OF 162,d& OF 49][email protected][g& OF 162,e& OF 49][email protected][g& OF 162,f& OF 49]>2 THEN INCR sc&:EXIT h&=g&-1 IF h&<>z& AND @nptr[h& OF 162,a& OF 49][email protected][h& OF 162,b& OF 49][email protected][h& OF 162,c& OF 49][email protected][h& OF 162,d& OF 49][email protected][h& OF 162,e& OF 49][email protected][h& OF 162,f& OF 49]>2 THEN INCR sc&:EXIT NEXT NEXT NEXT NEXT NEXT NEXT NEXT ' IF sc&>tst& THEN tst&=sc&:dlt&=z& ' NEXT ' FUNCTION=-1 END FUNCTION
Comment