| Mirage Source http://www.miragesource.net/forums/ |
|
| Speed testing http://www.miragesource.net/forums/viewtopic.php?f=193&t=4398 |
Page 1 of 1 |
| Author: | GIAKEN [ Sat Sep 20, 2008 6:14 pm ] |
| Post subject: | Speed testing |
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! |
|
| Author: | GIAKEN [ Sat Sep 20, 2008 6:26 pm ] |
| Post subject: | Re: Speed testing |
Alright done 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. |
|
| Author: | Lea [ Sat Sep 20, 2008 7:09 pm ] |
| Post subject: | Re: Speed testing |
What are your compiler optimization flags set at? |
|
| Author: | GIAKEN [ Sat Sep 20, 2008 7:22 pm ] |
| Post subject: | Re: Speed testing |
Not using any optimizations and I'm on an AMD Turion 64 X2 2.00 GHz. |
|
| Author: | Lea [ Sat Sep 20, 2008 7:44 pm ] |
| Post subject: | Re: Speed testing |
Why not? |
|
| Author: | Lea [ Sat Sep 20, 2008 9:54 pm ] |
| Post subject: | Re: Speed testing |
that would be something to test, eh? Longs are faster than Integers, btw, there's numerous places saying this. |
|
| Author: | GIAKEN [ Sat Sep 20, 2008 10:09 pm ] |
| Post subject: | Re: Speed testing |
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. |
|
| Author: | Lea [ Sat Sep 20, 2008 10:55 pm ] |
| Post subject: | Re: Speed testing |
In VB6 longs are 32 bit. Integers are 16 bit. |
|
| Author: | GIAKEN [ Sat Sep 20, 2008 11:07 pm ] |
| Post subject: | Re: Speed testing |
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. |
|
| Author: | GIAKEN [ Sun Sep 21, 2008 12:56 am ] |
| Post subject: | Re: Speed testing |
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. |
|
| Author: | Bakekitsune [ Sun Sep 21, 2008 3:09 pm ] |
| Post subject: | Re: Speed testing |
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. ![]()
|
|
| Author: | Jacob [ Sun Sep 21, 2008 6:55 pm ] |
| Post subject: | Re: Speed testing |
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? |
|
| Author: | GIAKEN [ Mon Sep 22, 2008 12:46 am ] |
| Post subject: | Re: Speed testing |
Did 2 more tests and updated to the top of the list. |
|
| Author: | JokeofWeek [ Thu Oct 09, 2008 1:41 am ] |
| Post subject: | Re: Speed testing |
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 |
|
| Author: | GIAKEN [ Thu Oct 09, 2008 1:59 am ] |
| Post subject: | Re: Speed testing |
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. |
|
| Author: | Coke [ Thu Oct 09, 2008 2:21 pm ] |
| Post subject: | Re: Speed testing |
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 |
|
| Author: | Jacob [ Thu Oct 09, 2008 3:05 pm ] |
| Post subject: | Re: Speed testing |
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. |
|
| Author: | GIAKEN [ Thu Oct 09, 2008 10:37 pm ] |
| Post subject: | Re: Speed testing |
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. |
|
| Author: | Dragoons Master [ Sun Oct 12, 2008 7:34 pm ] |
| Post subject: | Re: Speed testing |
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 To:Select Case l Case 1 b = True Case 2 b = True Case 3 b = True Case 4 b = True End Select 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 |
|
| Author: | Bakekitsune [ Tue Oct 28, 2008 7:10 am ] |
| Post subject: | Re: Speed testing |
JokeofWeek wrote: Thus, ZeroMemory is much faster Don't get too excited 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. 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. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|