Mirage Source

Free ORPG making software.
It is currently Tue Jun 04, 2024 7:50 pm

All times are UTC




Post new topic Reply to topic  [ 20 posts ] 
Author Message
 Post subject: Speed testing
PostPosted: Sat Sep 20, 2008 6:14 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
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 ;)

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.

<1 Versus =0
Unfortunately, doing <1 and =0 will result in the same speed. No gain or loss on either side.

Val() versus CByte/CInt/CLng
I just did a Val() versus CByte/CInt/CLng! With 10 million cycles Val() took about 10 seconds and the proper Conversion functions took less than a second for each.

CByte was fastest, CLng was second fastest, and CInt was the slowest of the three.

If checks versus And
I did 10 If checks and then I did 10 checks with And. I did this with a 10 million cycle and the And took about 18 seconds and the If took 10 seconds.

RECOMMEND MORE TESTS!

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Last edited by GIAKEN on Mon Sep 22, 2008 12:45 am, edited 5 times in total.

Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sat Sep 20, 2008 6:26 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Alright done :D

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.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sat Sep 20, 2008 7:09 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
What are your compiler optimization flags set at?

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sat Sep 20, 2008 7:22 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Not using any optimizations and I'm on an AMD Turion 64 X2 2.00 GHz.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sat Sep 20, 2008 7:44 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
Why not?

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sat Sep 20, 2008 9:54 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
that would be something to test, eh?

Longs are faster than Integers, btw, there's numerous places saying this.

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sat Sep 20, 2008 10:09 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
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.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sat Sep 20, 2008 10:55 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
In VB6 longs are 32 bit. Integers are 16 bit.

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sat Sep 20, 2008 11:07 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
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.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sun Sep 21, 2008 12:56 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
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.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sun Sep 21, 2008 3:09 pm 
Offline
Regular
User avatar

Joined: Sat Feb 10, 2007 10:52 pm
Posts: 49
Location: Melbs Australia
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

Image

_________________
Image
______________________________________________________________________________
www.animephantom.com


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sun Sep 21, 2008 6:55 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
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?


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Mon Sep 22, 2008 12:46 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Did 2 more tests and updated to the top of the list.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Thu Oct 09, 2008 1:41 am 
Offline
Knowledgeable
User avatar

Joined: Sun Nov 19, 2006 6:59 pm
Posts: 213
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 ;) Just wanted to test it out :P

_________________
Image


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Thu Oct 09, 2008 1:59 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
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.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Thu Oct 09, 2008 2:21 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Aug 17, 2006 5:27 pm
Posts: 866
Location: United Kingdom
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


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Thu Oct 09, 2008 3:05 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
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.


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Thu Oct 09, 2008 10:37 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
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.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Sun Oct 12, 2008 7:34 pm 
Offline
Pro
User avatar

Joined: Mon May 29, 2006 3:26 pm
Posts: 493
Location: São Paulo, Brasil
Google Talk: blackagesbr@gmail.com
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

_________________
http://www.blackages.com.br
Image
Dave wrote:
GameBoy wrote:
www.FreeMoney.com
I admit I clicked. I immediately closed upon realizing there was, in fact, no free money.
Robin wrote:
I love you and your computer.Marry me.


Top
 Profile  
 
 Post subject: Re: Speed testing
PostPosted: Tue Oct 28, 2008 7:10 am 
Offline
Regular
User avatar

Joined: Sat Feb 10, 2007 10:52 pm
Posts: 49
Location: Melbs Australia
JokeofWeek wrote:
Thus, ZeroMemory is much faster ;) Just wanted to test it out :P


Don't get too excited :D 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. :)

_________________
Image
______________________________________________________________________________
www.animephantom.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group