Page 1 of 1
Select : Case : EndSelect Benchmarks?
Posted: Wed Nov 05, 2003 2:23 am
by Akuma no Houkon
I havent had a chance yet (havent been on windows in ages) but has anyone benchmarked the PureBasic Select structure against VisualBasic and PowerBasic's Select structure?
I know the Select structure in PureBasic isnt that flexible (no ranges, multiple values etc..) but does anyone know its speed in comparison? I have a 70 item Select list that is looped thousands of times through and require the utmost speed. PowerBasic has optimization commands and VisualBasic auto optimises based on the type of Cases you have, what is PureBasic's take on the Select structure?
Regaurdless of the results does anyone have any methods that could make a Select structure faster? looping through 70+ cases (all bytes)
Posted: Wed Nov 05, 2003 2:37 am
by Shannara
I know in VB, using byte variables instead of Int32 (VB misnamed it as Longs) is slower. A REAL Long is basically an Int64. Anyways, There was a timer post not to long ago that allows you to time procedure length, could do the same with the select cases.. I know in VB, the Select Cases are faster then IF...Then, if implimented correctly.
Sorry I couldn't be of more help.
Posted: Wed Nov 05, 2003 4:07 am
by Codemonger
A Long is faster because it is native to the 32 bit cpu
Posted: Wed Nov 05, 2003 8:57 am
by Balatro
For speed-critical code I use If / ElseIf / EndIf rather than Select / Case / EndSelect, but that's only because most other Basic-dialects I've used have slow Select against If. PB's Select does seem quite fast though... Has anyone benchmarked thousands of Select loops against similar If-loops in PB?
~ B
Posted: Wed Nov 05, 2003 12:07 pm
by Akuma no Houkon
Balatro wrote:For speed-critical code I use If / ElseIf / EndIf rather than Select / Case / EndSelect, but that's only because most other Basic-dialects I've used have slow Select against If. PB's Select does seem quite fast though... Has anyone benchmarked thousands of Select loops against similar If-loops in PB?
~ B
I have always found it the opposite, and even PowerBasic and Visuabasic and QuickBasic's documentation says otherwise. It says that Select Case is used for faster operations because it only has to evalatate the lefthand side once.
Select String1
Case String2
Case String3
EndSelect
In most languages would evaluate String1 once, String2 once ance String3 once.
IF String1 = String2
Elseif String1 = String3
EndIf
Would Evaluate string1 TWICE, string2 and 3 once. During IF operations you have an extra evlauation compared to Select. And if you use PowerBasics Select Case As Const you get extreeme speed because it creates dynamic jump tables. I have benchmarked IF compared to Select in many basic dialects and Select has always come out on top.
I just want to know how fares PureBasic in this. I want to know if it will be worth using PureBasic for my windows version of my app not just the linux version.
Posted: Wed Nov 05, 2003 1:02 pm
by Froggerprogger
Here the following code gives IF is faster than SELECT as result:
Code: Select all
#max = 1000000000
Global a.l, b.l
starttime = GetTickCount_()
For i=0 To #max
If a=0 : b=0
ElseIf a=1 : b=1
ElseIf a=2 : b=2
Else : b=3
EndIf
Next
time = GetTickCount_() - starttime
MessageRequester("",Str(time)+"ms with IF:ELSEIF:ELSE",0)
starttime = GetTickCount_()
For i=0 To #max
Select a
Case 0 : b=0
Case 1 : b=1
Case 2 : b=2
Default : b=3
EndSelect
Next
time = GetTickCount_() - starttime
MessageRequester("",Str(time)+"ms with SELECT:CASE:DEFAULT",0)
IF lasts about 3500ms, SELECT about 4300ms.
Posted: Wed Nov 05, 2003 1:50 pm
by Akuma no Houkon
I did that SAME code (modified slightly for the specific language) on PureBasic (windows) VisualBasic6 and PowerBasic7 and this is my results: Note this is with any debugger (if available) turnned off. I tested multiple times to be sure they were accurate numbers. This is an unbiased test as I use all 3 languages.
PureBasic IF = 3146
PureBasic SELECT = 4332
PowerBasic IF = 3147
PowerBasic SELECT = 22079
PowerBasic SELECT (optimized) = 8789
VisualBasic IF = 1575
VisualBasic SELECT = 1571
Although VB and PowerBasic has a more flexible Select and allows for things like:
Case "Hey", "this", > 10, 1 to 15
etc.... I am sure if PureBasic had to check all those possiblities it would probably be alot slower than it is. And note that the specs change radically the more options you put in, 50 differnt options in the SELECT and PowerBasics blows VisualBasics out of the water. (havent tested PureBasic with 50 options yet)
But you seem to be right that SELECT seems to be the slower choice all arround.