I am looking for a reference that explains how/why the scope of a variable affects performance. Here is an example of what I mean
Code:03/28/09 13:12:51.516 CPU - 1.794GHz. Stopwatch(HR) Freq. is 3,579,545 x86 Family 6 Model 13 Stepping 6 Address width - 32 Memory - 2.0GB One - Procedure Two - Module Outer Loops(OL) = 7 Inner Loops(IL) = 262,144 Times given in ticks. 1 ms. = 10,000 ticks; 1,000 ms. = 1 second. Ticks / Loop Fastest? One 0.0194 1.2242 1.7381 -0.5139 OL Base IL One IL Two IL Difference (One - Two) 1 5,055 320,265 454,974 -134,709 2 5,086 320,411 454,639 -134,228 3 5,058 320,113 455,677 -135,564 4 5,093 320,022 455,077 -135,055 5 5,057 324,892 459,133 -134,241 6 5,247 319,998 455,082 -135,084 7 5,057 320,722 454,889 -134,167 Average 5,093 320,917 455,638 -134,721 (-13.472 ms./IL) 03/28/09 13:12:53.113 RunMode = CTRL-F5 End Dewayne Relative Speed Test Source Code Follows ' Const itms As Integer = 100 Dim TestData() As Integer Dim TestList As New List(Of Integer) Dim sum As Integer = 0 ' Private Function TestCase1() As Boolean 'One 'Test One Code Follows Dim sum As Integer = 0 For i As Integer = 0 To TestData.Length - 1 sum += TestData(i) Next 'End Test One Code Return True End Function ' Private Function TestCase2() As Boolean 'Two 'Test Two Code Follows sum = 0 For i As Integer = 0 To TestData.Length - 1 sum += TestData(i) Next 'End Test Two Code Return True End Function ' Private Sub _init() 'Code needed to get the Test to run. NOT part of the timing. 'Only called once!!! TestList.Clear() For x As Integer = 1 To itms TestList.Add(Short.MaxValue) Next TestData = TestList.ToArray End Sub




Reply With Quote