I noticed a slowish loop in my code, but after optimizing it a little, I got a much bigger speed increase than expected. On my laptop, the tix in the second loop below can exceed the first by as much as 150x or more. The loops do the same task, and it doesn't seem like there should be a big difference. I'm wondering if it might just be my computer, or maybe an error somewhere in the code. :thinking:
Code:
#COMPILE EXE #DIM ALL %MLEN = 5 %LOSIZE = &h04000 %HISIZE = 2 * %LOSIZE + %LOSIZE \ 2 %LOOPCNT = &h80000 \ %LOSIZE - 1 FUNCTION PBMAIN () AS LONG LOCAL ii, ii2, n AS LONG, t, t2 AS QUAD LOCAL qx2 AS STRING n = %HISIZE / %MLEN qx2 = STRING$(2000000, "5") DIM arr40(%LOOPCNT) AS STRING * %HISIZE AT STRPTR(qx2) DIM p(n) AS EXT, o(n) AS EXT FOR ii2 = 0 TO %LOOPCNT STEP 2 TIX t FOR ii = 0 TO n - 1 p(ii) = VAL(PEEK$(VARPTR(arr40(ii2)) + ii * %MLEN, %MLEN)) o(ii) = VAL(PEEK$(VARPTR(arr40(ii2)) + (ii+1) * %MLEN, %MLEN)) NEXT TIX END t NEXT FOR ii2 = 0 TO 3 STEP 2 'only do 2 loops for test TIX t2 FOR ii = 0 TO n - 1 p(ii) = VAL(MID$(arr40(ii2), ii * %MLEN + 1, %MLEN)) o(ii) = VAL(MID$(arr40(ii2+1), ii * %MLEN + 1, %MLEN)) NEXT TIX END t2 ? "PEEK time = " & STR$(t) & $CRLF & "MID time = " & STR$(t2) & $CRLF & "PEEK is" & STR$(t2 \ t) & "x faster" NEXT ? "Done" END FUNCTION
Comment