marcuslee
02-09-2008, 23:37
I found the INCR keyword just a few minutes ago, so I decided to give it a speed test. I used a speed test that is in the same section of this forum. I believe that the master himself wrote it. (Eros, that is!) My programming skills are limited, so I usually have to adapt what other people write.
Anyway, getting back on target. The following test takes about 31 or 32 msec to perform. After running it several times, the test only took 15 or 16 msecs. (I don't know the reason for the boost of speed.)
'---
' Sample script to demonstrate how fast INCR is
' The below function is resolved MaxCount times
' This script was adapted from another script (almost exactly like this one)
'---
'---Some predefined values
DIM n_str AS EXT VALUE 100
DIM n_lvl AS EXT VALUE 100
DIM n_wp AS EXT VALUE 100
DIM n_vit AS EXT VALUE 100
DIM n_adef AS EXT VALUE 100
DIM MaxCount AS LONG value 100000
dim x as integer value 1
'--Results and counters
DIM result AS EXT
DIM counter AS LONG
'---For time measuring
DIM T1 AS quad
DIM T2 AS quad
'---Used for string output
DIM Message AS STRING
'---Here we go ...
'---Ask if ...
Message = "This program will time increasing the value of x " & MaxCount & " times.\n"
Message += "Please press Yes to go on, NO to Stop\n"
DIM lResult AS LONG = MSGBOX(0, Message, %MB_YESNO, "Continue?")
IF lResult <> %IDYES THEN
STOP
END IF
'---Get initial time
T1 = gettickcount
'---Loops and get result
FOR counter = 1 TO MaxCount
incr x
NEXT
'---Get final time
T2 = gettickcount
'---Show results
MSGBOX 0, "mSecs:" & $tab & FORMAT$(T2 - T1, "#0") & $CRLF & _
"Result:" & $tab & result & $crlf & _
""
I wanted to compare INCR with the usual way I've incremented in the past. (X=X+1) Just changing the one line (as shown below) made the test take several msecs longer. This test usually ran around 47 msecs, though a few times it did come in at 32 msecs (I guess for the same reason INCR was faster sometimes).
'---Loops and get result
FOR counter = 1 TO MaxCount
x=x+1
NEXT
Why is INCR faster than X=X+1?
I'm sure there is some technobabble to explain this.
Mark
Anyway, getting back on target. The following test takes about 31 or 32 msec to perform. After running it several times, the test only took 15 or 16 msecs. (I don't know the reason for the boost of speed.)
'---
' Sample script to demonstrate how fast INCR is
' The below function is resolved MaxCount times
' This script was adapted from another script (almost exactly like this one)
'---
'---Some predefined values
DIM n_str AS EXT VALUE 100
DIM n_lvl AS EXT VALUE 100
DIM n_wp AS EXT VALUE 100
DIM n_vit AS EXT VALUE 100
DIM n_adef AS EXT VALUE 100
DIM MaxCount AS LONG value 100000
dim x as integer value 1
'--Results and counters
DIM result AS EXT
DIM counter AS LONG
'---For time measuring
DIM T1 AS quad
DIM T2 AS quad
'---Used for string output
DIM Message AS STRING
'---Here we go ...
'---Ask if ...
Message = "This program will time increasing the value of x " & MaxCount & " times.\n"
Message += "Please press Yes to go on, NO to Stop\n"
DIM lResult AS LONG = MSGBOX(0, Message, %MB_YESNO, "Continue?")
IF lResult <> %IDYES THEN
STOP
END IF
'---Get initial time
T1 = gettickcount
'---Loops and get result
FOR counter = 1 TO MaxCount
incr x
NEXT
'---Get final time
T2 = gettickcount
'---Show results
MSGBOX 0, "mSecs:" & $tab & FORMAT$(T2 - T1, "#0") & $CRLF & _
"Result:" & $tab & result & $crlf & _
""
I wanted to compare INCR with the usual way I've incremented in the past. (X=X+1) Just changing the one line (as shown below) made the test take several msecs longer. This test usually ran around 47 msecs, though a few times it did come in at 32 msecs (I guess for the same reason INCR was faster sometimes).
'---Loops and get result
FOR counter = 1 TO MaxCount
x=x+1
NEXT
Why is INCR faster than X=X+1?
I'm sure there is some technobabble to explain this.
Mark