Mirage Source
Speed testing - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51)
+----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44)
+----- Thread: Speed testing (/showthread.php?tid=2149)



Speed testing - GIAKEN - 20-09-2008

Alright...so I'm going to be doing some speed testing!

Whatever Dugor said
It's faster to do "If IsNumeric(Check) Then Check = CInt(Check)" than Check = Val(Check). So don't use Val()!

If statements versus Select Case
Select Case is twice as fast as If statements. (If statements were almost 4000ms and select case was 1600ms)

Not versus =False
If Not Check Then is faster than If Check = False Then.

Long versus all other numerical data types
Long is the fastest variable to use in a loop compared to bytes, integers, singles, doubles, and currency.

Byte versus Boolean
You think If Blah = 1 Then is faster than If Blah = True Then? WRONG! Boolean comparison is faster than byte comparison Wink

If Check versus If Check = True
If Check Then is faster than If Check = True Then.

Comparing Longs, Integers, Bytes, and Strings
It's fastest to compare Longs, Integers is second fastest, Bytes is third, and Strings are the slowest to compare. With 10 million cycles they all did around 1 second and weren't really that much faster than the other (about 100 ms), but strings did almost 2 seconds...

=True versus =1
=True appears to be faster than =1! With 10 million cycles =True did about half a second and =1 did 1 second.

[size=150]


Re: Speed testing - GIAKEN - 20-09-2008

Alright done Big Grin

Integers are like 20 ms faster than Longs with 10 million cycles, Longs were like 50 ms faster than Bytes, and they were all about a second faster than strings.


Re: Speed testing - GIAKEN - 20-09-2008

Not using any optimizations and I'm on an AMD Turion 64 X2 2.00 GHz.


Re: Speed testing - GIAKEN - 20-09-2008

It depends if you're using 32-bit or 64-bit. Since I'm on a 32-bit and Longs are 64-bit they have to be worked in 32-bit, while Integers are 32-bit they go straight through.


Re: Speed testing - GIAKEN - 20-09-2008

Lea Wrote:In VB6 longs are 32 bit. Integers are 16 bit.

Oh...fuck. Well I don't know why then all I know is what the results are. Integer was really close to Long...maybe like 20 ms apart with 10 million cycles.


Re: Speed testing - GIAKEN - 21-09-2008

Added 4 new speed comparisons.

Also I was wrong about the Long versus Integer. I think I read the results backwards...anyways, Long is faster than Integer.


Re: Speed testing - Bakekitsune - 21-09-2008

Usually on x86 CPU's Long(32) is faster than Integer(16).

This might be of help for string optimisation, the achilles heel of vb6.

[Image: stringopt2a.gif]

[Image: stringopt2b.gif]


Re: Speed testing - Jacob - 21-09-2008

DFA Wrote:comparing Val() to CInt() (and others) is not really a good plan
Val is like the Variant of casting functions

Cint("AAA") = RTE13
Val("AAA") = 0

but yeah, i recommend to use proper casting functions for speed vs Val

also, i've noticed you guys like to use Parse$()
the $ is not needed because it indicates a string, Parse() is an array of Strings, no need to specific that its a string when it already knows...

For the CInt("AAA") = RTE13, couldn't you do

If IsNumeric("AAA") before your conversion?
If so, what's the speed difference between Val() and checking for isnumeric then converting?


Re: Speed testing - GIAKEN - 22-09-2008

Did 2 more tests and updated to the top of the list.


Re: Speed testing - JokeofWeek - 09-10-2008

I was curious as to whether ZeroMemory was faster then erasing an array and redimming it for temporary arrays. Here is the code i used :

Code:
Dim I As Long, Counter As Byte
Dim timer As Long
Dim bytA() As Byte

    ReDim bytA(1000) As Byte
    
    For Counter = 1 To 5
    
    timer = GetTickCount
    
    For I = 1 To 1000000
        ZeroMemory bytA(0), 1001
    Next I
    
    Debug.Print "Zero Memory - " & GetTickCount - timer
    
    timer = GetTickCount
    
    For I = 1 To 1000000
        Erase bytA
        ReDim bytA(1000) As Byte
    Next I
    
    Debug.Print "Erasing - " & GetTickCount - timer
    
    Next Counter

And here were the results :

Code:
Zero Memory - 203
Erasing - 577
Zero Memory - 219
Erasing - 561
Zero Memory - 203
Erasing - 562
Zero Memory - 203
Erasing - 562
Zero Memory - 202
Erasing - 578

Thus, ZeroMemory is much faster Wink Just wanted to test it out Tongue


Re: Speed testing - GIAKEN - 09-10-2008

Yeah I did that test too a few weeks ago that I forgot about. We tried the oldest MS way to clear stuff, then a different way, and then the current ZeroMemory way. ZeroMemory is a lot faster than anything we tried.


Re: Speed testing - Coke - 09-10-2008

Just a note about Select Case, this is not faster than if's in C++ or Java, as it has to address every argument.

Anyone know why its faster in VB? Its technically impossible if its executed properly, my only conclusion is vb does something sick =P


Re: Speed testing - Jacob - 09-10-2008

Example code:
Code:
l = 2
    Select Case l
        Case 1
            b = True
        Case 2
            b = True
        Case 3
            b = True
        Case 4
            b = True
    End Select

Once it found case 2 and does what it needs to - it will exit the select case. So it looks like it doesn't evalute every expression.

Code:
l = 2
    If l = 1 Then
        b = True
    End If
    
    If l = 2 Then
        b = True
    End If
    
    If l = 3 Then
        b = True
    End If
    
    If l = 4 Then
        b = True
    End If

Doing that - it would have to check every statement unless you tell it to exit the sub or something.


Re: Speed testing - GIAKEN - 09-10-2008

Yeah...

Well I found that Select Case was faster than 2 If statements. It takes some time to open up, but that's where all the speed really takes place...

Select Case Whatever
Case 1
Case 2
End Select

Is faster than

If Whatever = 1 Then
If Whatever= 2 Then

But if you just used 1 case then it wouldn't be faster.


Re: Speed testing - Dragoons Master - 12-10-2008

Dugor Wrote:Example code:
Code:
l = 2
    Select Case l
        Case 1
            b = True
        Case 2
            b = True
        Case 3
            b = True
        Case 4
            b = True
    End Select

Once it found case 2 and does what it needs to - it will exit the select case. So it looks like it doesn't evalute every expression.

Code:
l = 2
    If l = 1 Then
        b = True
    End If
    
    If l = 2 Then
        b = True
    End If
    
    If l = 3 Then
        b = True
    End If
    
    If l = 4 Then
        b = True
    End If

Doing that - it would have to check every statement unless you tell it to exit the sub or something.

But you are comparing different things... You should compare:
Code:
l = 2
    Select Case l
        Case 1
            b = True
        Case 2
            b = True
        Case 3
            b = True
        Case 4
            b = True
    End Select
To:
Code:
l = 2
    If l = 1 Then
        b = True
    ElseIf l = 2 Then
        b = True
    ElseIf l = 3 Then
        b = True
    ElseIf l = 4 Then
        b = True
    End If



Re: Speed testing - Bakekitsune - 28-10-2008

JokeofWeek Wrote:Thus, ZeroMemory is much faster Wink Just wanted to test it out Tongue


Don't get too excited Big Grin Bitwise operators are more than 8 times faster than API Memory Handlers. Well API copymemory atleast, not sure about the others as i haven't tested.

So if you did an AND bitwise operation to any data type with &h0 (if not then &h0& which bitmasks as long) you should clear it much faster. :wink:

EDIT:

Oh yeh or if you do a XOR to itself.

Long Xor Long = 0. I'm not sure if you can Xor Byte Arrays in VB i can't be bothered checking tho. Smile