PDA

View Full Version : Equation solved 100000 times



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

kryton9
18-03-2007, 09:26
The first test took 250 ms and the second test 328 ms. Amazing to think 100,000 of anything that quickly.

matthew
18-03-2007, 10:37
Here are the Results from my 1.40GHz Celeron Laptop... 8)

1st - 281 msecs
2nd - 375 msecs

Petr Schreiber
18-03-2007, 11:17
Ouch :),

my Duron 850 does it in 635 - 653 ( really :D) ms


Bye,
Petr

kryton9
18-03-2007, 22:47
Petr when you compare your Duron to my AMD X2 4600 with 2 gigs ram, the performance is much better compared to the speed of the chip. I am dissappointed by my AMD X2, I just don't see the speed I thought I would with it. This is not one I built either. I bought an HP so I know it is configured optimal, so the speed is just not there like I thought it would be.

I also saw a video tutorial on an AMD X2 on terragen 2 by another 3dBuzz member and the renders were very very slow too. Although the articles on Tom's Hardware made it sound like the X2's were faster than Intels Dual Cores, I think in real world applications the Dual Core Intels are much faster.

ErosOlmi
18-03-2007, 22:53
Ken,

I compared a lot of speed tests between Intel P4 3.2Gh HyperT (HP machines) and my laptop Centrino Core 2 2Gh.
Core 2 is unbeatable. All tests run almost at double speed and consider thinBasic has no multithread handling inside.

So, Intel made a lot work on optimization. When I see task manager I can see both Core are working so it means even if thinBasic is not multithread in some way processor is able to make parallel optimizations.

Ciao
Eros

kryton9
18-03-2007, 22:56
Thanks Eros, I am thinking of making a new gaming machine in the future. I will ask at that time for input on cpu recommendations as I will do research also. The new intel's seem really great!! Glad you verified that with your tests too.