none
High resolution timing?

    Question

  • Is there anything with finer resolution than TimeSpan? I'm trying to profile some blocks of code and was hoping for something like QueryPerformanceCounter in the Win32 API - this is good down to microseconds.

    The profiling tool is not much use here as my dev environment is installed on XP and I've no desire to 'upgrade' to Vista.

    Thanks

    Jerry

     

    Wednesday, December 03, 2008 2:33 PM

Answers

  •  Jonathan - thanks for the contribution but it does not actually address the issue.

    In unmanaged  code I can call QueryPerformanceCounter() to get a very high resolution timestamp. If I bracket a segment of code with 2 such calls I can establish the chronological interval to within a few microseconds. Quite useful as a 'poor man's profiler'.

    My original posting asked if it were possible to achieve the same result in Silverlight. Since the runtime cannot make API calls directly the solution outlined above is clearly impossible.

    Note this has nothing to do with DispatcherTimer - this came from another (erroneous) poster.

    Kind regards

    Jerry

    Tuesday, December 09, 2008 11:14 AM

All replies

  •  Look to DispatcherTimer class

    Wednesday, December 03, 2008 4:35 PM
  • Sorry, don't understand the reference. How is this tick more accurate than TimeSpan? Can you elucidate?

    On a Windows XP box you are unlikely to get repeatable 10ms ticks, pretty much the minimum possible scheduling interval. Vista claims to do 1ms for 'pro' audiio - but generally the same as XP. Both a very long way from microsecond timing.

    Jerry. 

     

    Wednesday, December 03, 2008 6:54 PM
  • Hi Je8,

    Actually,  DispatcherTimer use TimeSpan as its Interval.   Therefore, I don't think it will be more  accurate than TimeSpan. 

    Timers are not guaranteed to execute exactly when the time interval occurs, but they are guaranteed to not execute before the time interval occurs. This is because DispatcherTimer operations are placed on the Dispatcher queue like other operations. When the DispatcherTimer operation executes is dependent on the other jobs in the queue and their priorities.

    If a System.Timers Timer is used in a WPF application, it is worth noting that the System.Timers Timer runs on a different thread then the user interface (UI) thread. In order to access objects on the user interface (UI) thread, it is necessary to post the operation onto the Dispatcher of the user interface (UI) thread using Invoke or BeginInvoke. For an example of using a System.Timers.Timer, see Disable Command Source via System Timer Sample. Reasons for using a DispatcherTimer opposed to a System.Timers. Timer are that the DispatcherTimer runs on the same thread as the Dispatcher and a DispatcherPriority can be set on the DispatcherTimer.

    Silverlight is a kind of client technology.  As far as I know, it is not designed for microsecond computing.  For  microsecond-level computing,  I am afraid that this queue is not the right place to discuss it.

    Best regards,

    Jonathan

     

    Tuesday, December 09, 2008 6:21 AM
  •  Jonathan - thanks for the contribution but it does not actually address the issue.

    In unmanaged  code I can call QueryPerformanceCounter() to get a very high resolution timestamp. If I bracket a segment of code with 2 such calls I can establish the chronological interval to within a few microseconds. Quite useful as a 'poor man's profiler'.

    My original posting asked if it were possible to achieve the same result in Silverlight. Since the runtime cannot make API calls directly the solution outlined above is clearly impossible.

    Note this has nothing to do with DispatcherTimer - this came from another (erroneous) poster.

    Kind regards

    Jerry

    Tuesday, December 09, 2008 11:14 AM
  • Hi Je8,

    Note this has nothing to do with DispatcherTimer - this came from another (erroneous) poster.
     

    Yes.  I got this.  

    I understand that you want to measure elapsed time for one interval, or the total of elapsed time across multiple intervals.  Something like Stopwatch.   However, currently, it is not achievable in Silverlight.  Thanks.

    Best regards,

    Jonathan

    Tuesday, December 09, 2008 9:49 PM