|
-
Jun 9th, 2007, 10:16 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] For...Next vs. Do...While
When I open my assemblies in Reflector, my for...next loops are rewritten like so:
Original Loop:
vb.net Code:
For i As Int32 = 0 To 30 Step 1
' Do something
Next i
Rewritten Loop:
vb.net Code:
Dim i As Integer
Do While (i <= 30)
' Do something
i += 1
Loop
I have also seen (and used):
vb.net Code:
Dim i As Integer
Do
' Do something
i += 1
Loop While (i <= 30)
Is there any performance difference between those? Or any difference other than the obvious aesthetic one?
Prefix has no suffix, but suffix has a prefix.
-
Jun 10th, 2007, 01:24 AM
#2
Re: [2005] For...Next vs. Do...While
I don't think there should be any significant difference. Although I would recommend using Integer instead of Int32. Because for two reasons:
1. Integer is faster then Int32
2. Integer will work in 64bit system but Int32 will throw an exeption.
Last edited by VBDT; Jun 10th, 2007 at 01:31 AM.
-
Jun 10th, 2007, 03:57 AM
#3
Re: [2005] For...Next vs. Do...While
 Originally Posted by Troy Lundin
Is there any performance difference between those? Or any difference other than the obvious aesthetic one?
No, that's just how For loops get compiled to bytecode.
 Originally Posted by VBDT
1. Integer is faster then Int32
As far as I know, Integer is mapped to either Int32 or Int64 depending on the platform, so I can't see how this could be true.
-
Jun 10th, 2007, 12:34 PM
#4
Re: [2005] For...Next vs. Do...While
 Originally Posted by penagate
No, that's just how For loops get compiled to bytecode.
As far as I know, Integer is mapped to either Int32 or Int64 depending on the platform, so I can't see how this could be true.
Hi penagate, This is from MSDN:
"The Integer data type provides optimal performance on a 32-bit processor. The other integral types are slower to load and store from and to memory."
-
Jun 10th, 2007, 05:38 PM
#5
Thread Starter
Hyperactive Member
Re: [RESOLVED] [2005] For...Next vs. Do...While
Are you positive that the "other integral types" it mentions are not Byte, Short and Long?
Prefix has no suffix, but suffix has a prefix.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|