tag:blogger.com,1999:blog-1501586010252802469.post8604647704226410012..comments2023-05-05T18:11:21.639+03:00Comments on Liran Chen's Blog: DateTime.Now in v4.0 Causes Dynamic Memory AllocationsLiran Chenhttp://www.blogger.com/profile/11833132955994920741noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-1501586010252802469.post-15062465261520979472011-08-22T20:41:04.424+03:002011-08-22T20:41:04.424+03:00@Kamron,
If you are required to obtain the current...@Kamron,<br />If you are required to obtain the current time at a very high precision, using DateTime.Now perhaps won't be a suitable solution for you, regardless of its "side effects", due to the fact that its only accurate up to the operating system's "timer tick" that by default usually revolves around 15ms.<br />One way to obtain a better precision is to sample the current time once (UTC time) and the initialize a Stopwatch instance. Afterwards, each time you'd like to sample the current time, you should check the current value of your stopwatch and add it to the previously sampled DateTime value.<br />Since the Stopwatch class has a much better precision than Windows's internal clock (being supported by your machine's hardware), you could achieve better accuracy.Liran Chenhttps://www.blogger.com/profile/11833132955994920741noreply@blogger.comtag:blogger.com,1999:blog-1501586010252802469.post-23473929840128964382011-08-22T20:14:48.776+03:002011-08-22T20:14:48.776+03:00The API work around is not very desirable. I have...The API work around is not very desirable. I have a program that has 900 instances of DateTime.Now (.NET Framework 4.0) including logging. The program requires microsecond precision and high reliability.<br />Are there any other options?Kamron Batmanhttps://www.blogger.com/profile/06087933120992919584noreply@blogger.comtag:blogger.com,1999:blog-1501586010252802469.post-22202313969042622102010-09-29T18:04:00.126+02:002010-09-29T18:04:00.126+02:00Glad someone is paying attention :)
Nice work w/wi...Glad someone is paying attention :)<br />Nice work w/windbg - it's been many years since i've used it. For many (timing) purposes, people can just call getTicks() - hopefully there's nothing hidden in there!Michael Robinhttps://www.blogger.com/profile/14508838938301983076noreply@blogger.comtag:blogger.com,1999:blog-1501586010252802469.post-5353574004953799602010-09-03T08:37:57.047+03:002010-09-03T08:37:57.047+03:00Thanks for the info!Thanks for the info!Anonymousnoreply@blogger.com