Re: Performance hit because of Datetime.Now

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Wed, 01 Oct 2008 11:23:50 -0700, <chivateatul@xxxxxxxxx> wrote:

Actually I am writing a gui in winform, which handles live data, &
that data is displayed in a grid(3rd party grid), in which when any
cell has to paint it raises event for each cell & in that event
depending on our business logic, we need to take datetime.now & the
previous datetime.Now, to know the timedifference between earlier
event call & current event call for that cell & since live data
updates are at a high rate this event gets fired continuously.

Whatever the cost of retrieving DateTime.Now, it should pale in comparison to the cost of actually updating the GUI. It seems to me that if your data rate is so high that you're running into a performance issue with DateTime.Now, then one important fix you probably should make is to throttle the GUI update.

The user can only keep track of so much information at once anyway, and by throttling the GUI update, you not only eliminate whatever marginal influence the call to DateTime.Now might have, you also help ensure that the application and overal computer remains more responsive, since you don't wind up spending all your time trying to keep the UI up-to-date.

Keeping track of invalidated displayed data and updating the UI once a second, or even once every half second, would surely not in any way diminish the user experience, but would significantly improve any performance issue you're having with respect to redrawing the UI.

Note also that if all you care about is elapsed time, you may find that a better class to use is the Stopwatch class. This would be with or without improvements as described above.

Overall
gui is in a good shape to handle that data, but we are further
optimizing it at all levels, and there we find out problem with
DateTime.Now.

I still find it difficult to understand how DateTime.Now could be causing a bottleneck with respect to GUI updating. Perhaps if you could post a concise-but-complete code sample that demonstrated the problem, we could see why it is you are able to update the UI so quickly that the relatively tiny cost of calling DateTime.Now (even in the inefficient way) is dominating your performance data.

But in any case, it seems likely to me that at the very least, you can dramatically improve your performance by not issuing a redraw every single time some data shows up. Just update periodically, at a slower rate that is more in line with what a human user is capable of perceiving.

Actually my question is, has anyone idea that there is a problem with
DateTime.Now? Is it documented anywhere(MSDN???)

Even with Brian's observation that DateTime.Now takes 50x longer than DateTime.UtcNow, I remain unconvinced that there's "a problem with DateTime.Now". It may be too slow for what you're trying to do with it, but all that means is that you're not using it in an appropriate way.

Pete
.



Relevant Pages

  • Re: IS THERE ANY EQUIVALENT TO DISPOSE()?
    ... Perhaps when you only have a partial result, but you don't want to have the GUI doing updates for every single cell. ... to start I had a key get the next customer details up. ... Unemployed English Java programmer ...
    (comp.lang.java.programmer)
  • Re: Development tools for VMS
    ... > cell, GUI, browser)? ... your user interface w/o impacting your biz apps. ... >>either a VT character cell terminal or a PC running VT emulation. ...
    (comp.os.vms)
  • Re: Buying a Sun SPARC Classic, can anyone help me?
    ... If the cost of "buying" is more or less the cost of trading ... > in a GUI. ... If you are just after the fun of having a SPARC system it's ... Alternatively, you could of course work on your resume instead, but I ...
    (comp.sys.sun.hardware)
  • Re: Performance - Console vs. GUI
    ... The only updating I had planned on doing was ... Basically there are people that say GUI is ... > noticeable performance difference. ... > notice it in the grand scheme of things. ...
    (microsoft.public.vstudio.general)
  • Updating GUI & Running Program (AND accessing common variables!)
    ... I want to have something running in the background, while the GUI is ... //Other code setting things up and updating GUI ... I have yet to find a way to pass variables to the inner thread unless ...
    (comp.lang.java.gui)