ErosOlmi
18-03-2007, 09:11
A classical FOR/NEXT loop to show speed execution.
Under a Centrino Duo 2Ghz this script is executed in 200 milliseconds.
100000 iterations.
'---
' Sample script to demonstrate how fast thinBasic is
' The below function is resolved MaxCount times
'---
'---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
'--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 solve a simple math expression " & 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
result = (((n_str*85+n_lvl)*n_wp)-((n_vit*90+n_adef)*n_lvl))/2
NEXT
'---Get final time
T2 = gettickcount
'---Show results
MSGBOX 0, "mSecs:" & $tab & FORMAT$(T2 - T1, "#0") & $CRLF & _
"Result:" & $tab & result & $crlf & _
""
And here almost the same script but now calculation is performed by a specific function.
Execution times on a Centrino Duo 2GHz is about 590 milliseconds.
DIM n_str AS EXT VALUE 10000
DIM n_lvl AS EXT VALUE 10000
DIM n_wp AS EXT VALUE 10000
DIM n_vit AS EXT VALUE 10000
DIM n_adef AS EXT VALUE 10000
DIM Result AS EXT
DIM counter AS LONG
DIM MaxCount AS LONG = 100000
DIM T1 AS DOUBLE
DIM T2 AS DOUBLE
DIM Message AS STRING
Message = "This program will solve a simple math expression " & 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
T1 = TIMER
Result = 0
FOR counter = 1 TO MaxCount
result = CalcFormula
NEXT
T2 = TIMER
MSGBOX(0, _
"Seconds:" & $tab & $tab & FORMAT$(T2 - T1, "#0.000000") & $CRLF & _
"Result:" & $tab & $tab & result & $crlf & _
"" _
)
'---
' Formula calculation
'---
function CalcFormula() as ext
function = (((n_str*85+n_lvl)*n_wp)-((n_vit*90+n_adef)*n_lvl))/2
end function
Under a Centrino Duo 2Ghz this script is executed in 200 milliseconds.
100000 iterations.
'---
' Sample script to demonstrate how fast thinBasic is
' The below function is resolved MaxCount times
'---
'---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
'--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 solve a simple math expression " & 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
result = (((n_str*85+n_lvl)*n_wp)-((n_vit*90+n_adef)*n_lvl))/2
NEXT
'---Get final time
T2 = gettickcount
'---Show results
MSGBOX 0, "mSecs:" & $tab & FORMAT$(T2 - T1, "#0") & $CRLF & _
"Result:" & $tab & result & $crlf & _
""
And here almost the same script but now calculation is performed by a specific function.
Execution times on a Centrino Duo 2GHz is about 590 milliseconds.
DIM n_str AS EXT VALUE 10000
DIM n_lvl AS EXT VALUE 10000
DIM n_wp AS EXT VALUE 10000
DIM n_vit AS EXT VALUE 10000
DIM n_adef AS EXT VALUE 10000
DIM Result AS EXT
DIM counter AS LONG
DIM MaxCount AS LONG = 100000
DIM T1 AS DOUBLE
DIM T2 AS DOUBLE
DIM Message AS STRING
Message = "This program will solve a simple math expression " & 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
T1 = TIMER
Result = 0
FOR counter = 1 TO MaxCount
result = CalcFormula
NEXT
T2 = TIMER
MSGBOX(0, _
"Seconds:" & $tab & $tab & FORMAT$(T2 - T1, "#0.000000") & $CRLF & _
"Result:" & $tab & $tab & result & $crlf & _
"" _
)
'---
' Formula calculation
'---
function CalcFormula() as ext
function = (((n_str*85+n_lvl)*n_wp)-((n_vit*90+n_adef)*n_lvl))/2
end function