Visual-Studio-2008 – In VB 2008, why does the short circuit need to be longer than the integer?

In this example:

Sub Button1_Click(sender As Object, ByVal e As EventArgs) Handles Button1.Click< br /> Dim stopwatch1, stopwatch2 As New Stopwatch: Dim EndLoop As ULong = 10000

stopwatch1.Start()
For cnt As ULong = 1 To EndLoop
Dim Number1 As UInt32
For Number1 = 1 To 20000
Dim Number2 As UInt32 = 0
Number2 += 1
Next
Next
stopwatch1.Stop()

stopwatch2.Start()
For cnt As ULong = 1 To EndLoop
Dim Number1 As UShort
For Number1 = 1 To 20000
Dim Number2 As UShort = 0
Number2 += 1
Next
Next
stopwatch2.Stop()

Label1.Text = "UInt32: "& stopwatch1.ElapsedMilliseconds
Label2.Text = "UShort: "& stopwatch2.ElapsedMilliseconds
End Sub

For the UInt32 loop, I keep getting about 950 milliseconds, and for the UShort loop, it takes about 1900 milliseconds. If I add USho Change rt to Short and I will also get about 1900 ms.

Also, I can change the second loop to:

stopwatch2.Start( )
For cnt As ULong = 1 To EndLoop
Dim Number1 As Integer
For Number1 = 1 To 20000
Dim Number2 As Integer = 0
Number2 += 1< br /> Next
Next
stopwatch2.Stop()

The integer loop will always be 660 ms, while the UInt32 loop will be 950 ms.

With Short , Is the data type used by Integers faster than UShort and UInt32? If so, why?

I bet this is because the natural font size on your machine is 32 bits, and 16 bits The operation will actually put more pressure on the system to cut and shield these bits.

If you test on a 64-bit processor, the result of Int64 may be better than Int32…< /p>

Also, in .NET, all integer (up to 32-bit) arithmetic are automatically upgraded to int, so when you assign the result back to a short variable, you will cause an additional conversion step. The same applies to uint .

In this example:

Sub Button1_Click(sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim stopwatch1, stopwatch2 As New Stopwatch: Dim EndLoop As ULong = 10000

stopwatch1.Start()
For cnt As ULong = 1 To EndLoop
Dim Number1 As UInt32
For Number1 = 1 To 20000
Dim Number2 As UInt32 = 0
Number2 += 1
Next
Next
stopwatch1.Stop ()

stopwatch2.Start()
For cnt As ULong = 1 To EndLoop
Dim Number1 As UShort
For Number1 = 1 To 20000
Dim Number2 As UShort = 0
Number2 += 1
Next
Next
stopwatch2.Stop()

Label1.Text = "UInt32: "& stopwatch1.ElapsedMilliseconds
Label2.Text = "UShort:" & stopwatch2.ElapsedMilliseconds
End Sub

For the UInt32 loop, I keep getting about 950 milliseconds, and for the UShort loop, it takes about 1900 milliseconds. If I change UShort to Short, I also get about 1900 ms.

In addition, I You can change the second loop to:

stopwatch2.Start()
For cnt As ULong = 1 To EndLoop
Dim Number1 As Integer
For Number1 = 1 To 20000
Dim Number2 As Integer = 0
Number2 += 1
Next
Next
stopwatch2.Stop()

< p>The integer loop will always be 660 ms, and the UInt32 loop will be 950 ms.

Compared with Short, UShort and UInt32, is the data type used by Integers faster? If so, why?

I bet this is because the natural word size on your machine is 32 bits, and 16-bit operations will actually put more pressure on the system To cut and mask these bits.

If you test on a 64-bit processor, the results of Int64 may be better than Int32…

In addition, in .NET , All integer (up to 32 bits) arithmetic will be automatically upgraded to int, so when you assign the result back to a short variable, you will cause an extra conversion step. The same applies to uint.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1951 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.