$ESCAPECHARS ON
$TYPECHECK ON
$INCLUDE "RAPIDQ.INC"
DECLARE FUNCTION CallAsmProc LIB "user32" ALIAS "CallWindowProcA" _
(Proc AS LONG, A1 AS LONG, A2 AS LONG, A3 AS LONG, _
A4 AS LONG) AS LONG
DEFBYTE TestShift16Array (0 TO 18) = _
{ _
&HC8, &H00, &H00, &H00, &H8B, &H4D, &H0C, &H8B, &H45, &H08, _
&HC1, &HE0, &H10, &HE2, &HF8, &HC9, &HC2, &H10, &H00 _
}
DEFINT ptrTestShift16
ptrTestShift16 = VARPTR (TestShift16Array(0))
FUNCTION TestShift16 (Arg1 AS LONG, Arg2 AS LONG) AS LONG
Result = CallAsmProc (ptrTestShift16, Arg1, Arg2, 0, 0)
END FUNCTION
DEFSNG sStart, sEnd, SHLTime, MUL256Time, MUL65536Time, ASMTime
DEFINT N, iCount, i
iCount = 500000
i = 123
PRINT " Can take some time\n 500000 Loops\n - i SHL 16\n - i * 256 * 256\n - i * 65536\n - i SHL 16 in ASM\n\n ... be Patient\n"
sStart = TIMER
FOR N = 1 TO iCount
i=i SHL 16
NEXT N
sEnd = TIMER
PRINT (STR$(iCount) & " Loops i SHL 16 Time : " & STR$(sEnd - sStart))
SHLTime = sEnd - sStart
sStart = TIMER
FOR N = 1 TO iCount
i = i * 256 * 256
NEXT N
sEnd = TIMER
PRINT (STR$(iCount) & " Loops i * 256 * 256 Time : " & STR$(sEnd - sStart))
MUL256Time = sEnd - sStart
sStart = TIMER
FOR N = 1 TO iCount
i = i * 65536
NEXT N
sEnd = TIMER
PRINT (STR$(iCount) & " Loops i * 65536 Time : " & STR$(sEnd - sStart))
MUL65536Time = sEnd - sStart
sStart = TIMER
i = TestShift16 (i, iCount)
sEnd = TIMER
PRINT (STR$(iCount) & " Loops Shift Asm Time : " & STR$(sEnd - sStart))
ASMTime = sEnd - sStart
PRINT ("\nASM is " & STR$(INT(MUL65536Time/ASMTime)) & " Time Faster than *65536")
DEFSTR sExit
INPUT "\n\n CR to QUIT \n\n", sExit
Application.Terminate
END
|