数组与List,如何提高运算速度
有两组随机生成的(0~99999)Int32数据A和B,将A按顺序判断在B中是否存在并记录在Boolean型的C中,我分别尝试了Array与List(Of T),在VS2010下以我的破电脑的速度Array大概需要4秒,而List(Of T)则要24秒,以下是我用Array和List(of T)的代码,请高手指点, 顺便问下有无秒杀的方法'Array处理
Dim A As Int32(), b As Int32(), c As Boolean(), i As Int32
ReDim A(65000), b(66666), c(65000)
Dim rAd As New System.Random
Dim Stp As New Stopwatch
Stp.Start()
For i = 0 To A.Length - 1
A(i) = rAd.Next(0, 99999)
Next
For i = 0 To b.Length - 1
b(i) = rAd.Next(0, 99999)
Next
For i = 0 To A.Length - 1
If Array.IndexOf(b, A(i)) >= 0 Then
c(i) = True
Else
c(i) = False
End If
Next
Me.Text = "Array测试" & (Stp.ElapsedMilliseconds) & "毫秒"
'List(Of T)处理
Dim A As New List(Of Int32)
Dim B As New List(Of Int32)
Dim C As New List(Of Boolean)
Dim rAd As New System.Random
Dim Stp As New Stopwatch
Stp.Start()
For i As Int32 = 0 To 65000
A.Add(rAd.Next(0, 99999))
Next
For j As Int32 = 0 To 66666
B.Add(rAd.Next(0, 99999))
Next
For k As Int32 = 0 To A.Count - 1
If B.Contains(A.Item(k)) = True Then
C.Add(True)
Else
C.Add(False)
End If
Next
Me.Text = "list(of int32)测试" & (Stp.ElapsedMilliseconds) & "毫秒"