I am running a pretty simple VB program that solves the Project Euler Problem 2 and I want to time the performance. My approach is:
StartTime = Timer()
Set streamer = CreateObject("Scripting.FileSystemObject")
Set writingWriter = streamer.GetStandardStream(1)
Dim n, nIterations, Temp1, Temp2, Collector
n = 4000000
nIterations = 0
Temp1 = 0
Collector = 0
Temp2 = 1
Do
Fib = Temp1 + Temp2
Temp2 = Temp1
Temp1 = Fib
Select Case Fib Mod 2
Case 0
Collector = Collector + Fib
End Select
Loop Until Fib > n
EndTime = Timer()
writingWriter.WriteLine("Solution is: " & Collector)
writingWriter.WriteLine("Code took " & EndTime - StartTime & " to execute")
The first time I ran the code I got the following output (my input is also included):
C:\Dev\cscript program.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
Solution is: 4613732
Code took 0.015625 to execute
Each subsequent execution (not changing anything) gives me the following:
C:\Dev\cscript program.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
Solution is: 4613732
Code took 0 to execute
Can someone explain what is going on here? It seems like the Windows Console has stored the value of Fib and is simply recalling it upon execution of the code. A friend running something similar (although he's using VBA) got the same result - each of his subsequent executions experienced a reduction in run-time.
Please note: I know this is a pretty simple approach, I'm just trying to get a feel for VB. Not a huge fan so far.