我有我的TickTimer類,所以我決定試一試。 我不得不增加數組的大小以注意不同之處。
自己測試一下。第一個確實更快。
Module Module1
Sub Main()
Dim A(10000, 20000) As Int16
Dim b(10000, 20000) As Int16
For n = 1 To 10000
For m = 1 To 20000
A(n, m) = 1
b(n, m) = 1
Next m
Next n
Dim firstTick As TickTimer = New TickTimer()
For n = 1 To 10000
For m = 1 To 20000
A(n, m) = b(n, m)
Next m
Next n
Console.WriteLine(firstTick.DeltaSeconds(""))
Dim secondTick As TickTimer = New TickTimer()
For m = 1 To 20000
For n = 1 To 10000
A(n, m) = b(n, m)
Next n
Next m
Console.WriteLine(secondTick.DeltaSeconds(""))
Console.ReadKey()
End Sub
End Module
Public Class TickTimer
Public currentTicks As Long
Public lastTicks As Long = System.DateTime.Now.Ticks
Public retVal As String
''' <summary>
''' Calculates the seconds it took since the class was instantiated until this method
''' is first invoked and for subsequent calls since the previous time the method was called
''' </summary>
''' <param name="message">Message (e.g. "The last query took ")</param>
''' <returns>The passed string followed by the seconds: " The last query took, 0.3456"</returns>
''' <remarks>To see how long it takes a method to execute instantiate this class at its
''' very begining and call this method just before it returns; Log the result with Debug.Writeln or something similar</remarks>
Public Function DeltaSeconds(ByVal message As String) As String
currentTicks = System.DateTime.Now.Ticks
retVal = String.Format("{0}, {1}", message.PadLeft(100), ((currentTicks - lastTicks)/ TimeSpan.TicksPerSecond).ToString().PadRight(15))
lastTicks = currentTicks
Return retVal
End Function
End Class
沒關係。 – Kevin
嗯,我想可能會有所作爲,但我們必須看到'A(int,int)'的定義。實際上,你不應該擔心它。 –
爲什麼不嘗試並找出答案? –