none
Code execution time precision RRS feed

  • Question

  • I've got a function whose execution time I'm measuring using DateTime.Now and TimeSpan.TotalMilliseconds.

    The execution time is either 0 or 15.664. There are no intermediate values. Why?
    Wednesday, August 6, 2008 2:10 PM

Answers

  • You're measuring the time within a time slice (0) or the time between time slices (15.664).  DateTime doesn't change within a time slice.  Use the stopwatch to measure execution times.
    • Marked as answer by mblandfo Wednesday, August 6, 2008 3:54 PM
    Wednesday, August 6, 2008 3:32 PM

All replies

  • You're measuring the time within a time slice (0) or the time between time slices (15.664).  DateTime doesn't change within a time slice.  Use the stopwatch to measure execution times.
    • Marked as answer by mblandfo Wednesday, August 6, 2008 3:54 PM
    Wednesday, August 6, 2008 3:32 PM
  • Thanks, that's exactly what I was looking for.....

    except it won't work for me because I'm using Silverlight and I get this error: "Attempt to access the method failed: StopWatch.QueryPerformanceFrequency(Int64 ByRef)"
    Wednesday, August 6, 2008 3:56 PM