{"id":97057,"date":"2017-09-21T07:00:00","date_gmt":"2017-09-21T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=97057"},"modified":"2019-03-13T01:17:03","modified_gmt":"2019-03-13T08:17:03","slug":"20170921-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20170921-00\/?p=97057","title":{"rendered":"How accurate are the various Windows time-querying functions?"},"content":{"rendered":"<p>Windows has a bunch of time-querying functions. One group of functions uses the system performance counter. These are as accurate as the hardware allows while still conforming to the basic requirements (such as running at a constant speed and being consistent among multiple processors). <\/p>\n<ul>\n<li><code>Query&shy;Performance&shy;Counter<\/code>     gives you the current performance counter, and<\/li>\n<li><code>Query&shy;Performance&shy;Frequency<\/code>     tells you the frequency of the performance counter.<\/li>\n<\/ul>\n<p>Another group uses the system timer, which usually means 55ms or 10ms, although <a HREF=\"https:\/\/msdn.microsoft.com\/library\/dd757624(v=vs.85).aspx\">the <code>time&shy;Begin&shy;Period<\/code> function<\/a> can be used to run the timer at a higher rate. <\/p>\n<ul>\n<li><code>Get&shy;Tick&shy;Count<\/code>,     <code>Get&shy;Tick&shy;Count64<\/code><\/li>\n<li><code>Get&shy;Message&shy;Time<\/code><\/li>\n<li><code>Get&shy;System&shy;Time<\/code>,     <code>Get&shy;Local&shy;Time<\/code>,     <code>Get&shy;System&shy;Time&shy;As&shy;File&shy;Time<\/code><\/li>\n<li><code>Query&shy;Interrupt&shy;Time<\/code>,     <code>Query&shy;Unbiased&shy;Interrupt&shy;Time<\/code><\/li>\n<\/ul>\n<p>And then there are the so-called precise&sup1; variants of the system timer functions. These take the system timer value and combine it with the system performance counter to get a high-accuracy timestamp. It&#8217;s not only querying two timers, but it&#8217;s also doing additional computations to combine the values, so naturally this is slower than querying just one of the two timers, but hey, a fine wine takes time. <\/p>\n<ul>\n<li><code>Get&shy;System&shy;Time&shy;Precise&shy;As&shy;File&shy;Time<\/code>      \n<li><code>Query&shy;Interrupt&shy;Time&shy;Precise<\/code>,     <code>Query&shy;Unbiased&shy;Interrupt&shy;Time&shy;Precise<\/code> <\/li>\n<\/ul>\n<p>These high-accuracy functions give you the best of both worlds: Time correlated with real-world clocks, but with the accuracy of the system performance counter. But as noted, it comes at a performance cost. <\/p>\n<p>&sup1; Though to be pedantic, they should be called the <a HREF=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/\">accurate<\/a> variants. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of them are based on the system timer, but some are better.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-97057","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Most of them are based on the system timer, but some are better.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=97057"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97057\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=97057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=97057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=97057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}