{"id":4749,"date":"2024-11-19T13:44:00","date_gmt":"2024-11-19T13:44:00","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4749"},"modified":"2024-11-19T13:44:01","modified_gmt":"2024-11-19T13:44:01","slug":"using-perf_counter","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/timer-and-timing\/perf_counter\/using-perf_counter","title":{"rendered":"Using perf_counter"},"content":{"rendered":"\n<p>The perf_counter() function returns the float value of time in seconds. It uses a performance counter, i.e. a clock with the highest available resolution to measure a short duration. It includes time elapsed during sleep and is system-wide. The reference point of the returned value is undefined, so you must measure at the start and then compare to the end of the period you want to measure and compare the values<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Checking an IO operation completed within a time in uS<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\n\n    start_counter = time.perf_counter()\n    #Do something here you want to ensure occurs fast enough\n    GPIO.output(self._pd_sck, True)\n    GPIO.output(self._pd_sck, False)\n    end_counter = time.perf_counter()\n    if end_counter - start_counter >= 0.00006:\n            print('Not enough fast while reading data')<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The perf_counter() function returns the float value of time in seconds. It uses a performance counter, i.e. a clock with the highest available resolution to measure a short duration. It includes time elapsed during sleep and is system-wide. The reference point of the returned value is undefined, so you must measure at the start and [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[374],"tags":[],"class_list":["post-4749","post","type-post","status-publish","format-standard","hentry","category-perf_counter"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4749"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4749\/revisions"}],"predecessor-version":[{"id":4750,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4749\/revisions\/4750"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}