snufse Posted May 12, 2006 Posted May 12, 2006 I am using the following code to get the elapsed time for a process. The difference is calculated and added to a list box. On first pass the difference in time is calculated and on all subsequent passes elapsed time shows as zero? Here is the code: Do Dim FromTime As DateTime = DateTime.Now ... Here goes the code wich is a call to a stored procedure .... Dim ToTime As DateTime = DateTime.Now Dim TimeDifference As TimeSpan = ToTime.Subtract(FromTime) Dim DifferenceInMilliseconds As Double = TimeDifference.TotalMilliseconds ListBox1.Items.Add("Processing Time: " & DifferenceInMilliseconds.ToString & " ms") Loop Quote
Administrators PlausiblyDamp Posted May 12, 2006 Administrators Posted May 12, 2006 If you print the FromTime and ToTime out to the debug window are they different? It could be that it really is taking less than a millisecond... Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mskeel Posted May 14, 2006 Posted May 14, 2006 The behavior you are seeing (greater than zero on the first pass, zero on subsequent passes) is likely due to temporal caching in the loop. The first time through, the information needs to be loaded in memory, but because your are looping, the data stays in memory because it is used often over a short period of time. Also, perhaps the stopwatch class would be slightly more accurate? It could just be the same, but it seems to be built for this type of activity. If you are using .Net 2.0 this might be something to try to see if you can squeeze a little more precision out of your timing. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.