{"id":92,"date":"2011-05-22T08:12:13","date_gmt":"2011-05-22T08:12:13","guid":{"rendered":"http:\/\/devnot.wordpress.com\/?p=92"},"modified":"2011-05-22T08:12:13","modified_gmt":"2011-05-22T08:12:13","slug":"getting-the-tick-count-gettickcount-api-replacement","status":"publish","type":"post","link":"https:\/\/thomas-jansen.eu\/?p=92","title":{"rendered":"Getting the tick count  (GetTickCount API replacement)"},"content":{"rendered":"<p><span style=\"text-decoration:underline;\">System.Environment.TickCount<\/span><br \/>\nUse <em>System.Environment.TickCount<\/em> to get the number of milliseconds expired since session startup. Although this number is expressed in ms its actual resolution may be lower. A test on a I7 2.8GHZ CPU \/ Windows 7 64 Bit shows it&#8217;s interval is about 15 ms, also this value will wrap around, something to take in consideration.<\/p>\n<p><span style=\"text-decoration:underline;\">DateTime.Now.Ticks<\/span><br \/>\nYou can also use the <em>DateTime.Now.Ticks <\/em>which reports the number of &#8216;ticks&#8217; in a 100ns resolution since 12:00:00 midnight, January 1, 0001. Being a 64 bit value it will not wrap around and is more accurate. Again this is not its true resolution. A test on a I7 2.8GHZ CPU \/ Windows 7 64 Bit shows it&#8217;s interval is 10000 x 100ns = 1 ms.<\/p>\n<p><span style=\"text-decoration:underline;\">Exact timing, the StopWatch class<\/span><br \/>\nFor exact timing purposes you can better use the <em>System.Diagnostics.Stopwatch<\/em> class. It uses the high resolution timers which are far more better.<\/p>\n<p><strong>Note:<\/strong> On any CPU you are never alone, especially on a single core the threads and processes share the time available. If you want to perform detailed timing on a multi-core CPU\u00a0 you can use the CPU affinity mask trying to reserve a CPU core for your process alone (although you are never really sure the OS doesn&#8217;t share).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>System.Environment.TickCount Use System.Environment.TickCount to get the number of milliseconds expired since session startup. Although this number is expressed in ms its actual resolution may be lower. A test on a I7 2.8GHZ CPU \/ Windows 7 64 Bit shows it&#8217;s interval is about 15 ms, also this value will wrap around, something to take in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[76],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-c","tag-timing"],"_links":{"self":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92"}],"version-history":[{"count":0,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/92\/revisions"}],"wp:attachment":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}