Select : Case : EndSelect Benchmarks?

Everything else that doesn't fall into one of the other PB categories.
Akuma no Houkon
User
User
Posts: 77
Joined: Sun Nov 02, 2003 1:47 pm
Location: Washington
Contact:

Select : Case : EndSelect Benchmarks?

Post 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)
AMD 2600+, nVidia Geforce FX 5200 128 MB DDR, 512 DDR, RedHat 9
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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.
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

A Long is faster because it is native to the 32 bit cpu
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
Balatro
User
User
Posts: 15
Joined: Sun Oct 05, 2003 2:27 pm

Post 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
Akuma no Houkon
User
User
Posts: 77
Joined: Sun Nov 02, 2003 1:47 pm
Location: Washington
Contact:

Post 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.
AMD 2600+, nVidia Geforce FX 5200 128 MB DDR, 512 DDR, RedHat 9
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post 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.
%1>>1+1*1/1-1!1|1&1<<$1=1
Akuma no Houkon
User
User
Posts: 77
Joined: Sun Nov 02, 2003 1:47 pm
Location: Washington
Contact:

Post 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.
AMD 2600+, nVidia Geforce FX 5200 128 MB DDR, 512 DDR, RedHat 9
Post Reply