![]() |
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 ![]() 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 ![]() 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. ![]() ![]() Re: Speed testing - Jacob - 21-09-2008 DFA Wrote:comparing Val() to CInt() (and others) is not really a good plan 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 And here were the results : Code: Zero Memory - 203 Thus, ZeroMemory is much faster ![]() ![]() 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 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 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: But you are comparing different things... You should compare: Code: l = 2 Code: l = 2 Re: Speed testing - Bakekitsune - 28-10-2008 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. :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. ![]() |