{"id":1510,"date":"2020-06-05T21:37:47","date_gmt":"2020-06-05T13:37:47","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1510"},"modified":"2020-06-05T21:37:47","modified_gmt":"2020-06-05T13:37:47","slug":"python-time-%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1510","title":{"rendered":"Python time \u6a21\u5757"},"content":{"rendered":"<div>\nPython \u5185\u7f6e\u7684 time \u6a21\u5757\u53ef\u4ee5\u8ba9 Python \u7a0b\u5e8f\u8bfb\u53d6\u7cfb\u7edf\u65f6\u949f\u7684\u5f53\u524d\u65f6\u95f4\u3002<\/p>\n<h2>1 time.time() \u51fd\u6570<\/h2>\n<p>Unix \u7eaa\u5143\u6307\u7684\u662f 1970 \u5e74 1 \u6708 1 \u65e5 0 \u70b9\uff0c\u5373\u534f\u8c03\u4e16\u754c\u65f6\uff08UTC\uff09\u3002 time.time()\u51fd\u6570\u4f1a\u8fd4\u56de\u81eaUnix \u7eaa\u5143\u90a3\u4e00\u523b\u4ee5\u6765\u7684\u79d2\u6570\uff0c\u662f\u4e00\u4e2a\u6d6e\u70b9\u503c\uff0c\u8fd9\u4e2a\u6570\u5b57\u79f0\u4e3a UNIX \u7eaa\u5143\u65f6\u95f4\u6233\u3002 \uff08\u7531\u4e8e\u82f1\u6587\uff08CUT\uff0cCoordinated Universal Time\uff09\u548c\u6cd5\u6587\uff08TUC\uff09\u7684\u7f29\u5199\u4e0d\u540c\uff0c\u4f5c\u4e3a\u59a5\u534f\uff0c\u7b80\u79f0 UTC\u3002\uff09<br \/>\nUNIX \u7eaa\u5143\u65f6\u95f4\u6233\u53ef\u4ee5\u7528\u4e8e\u5256\u6790\u4ee3\u7801\u6027\u80fd\uff0c\u4e5f\u5c31\u662f\u6d4b\u91cf\u4e00\u6bb5\u4ee3\u7801\u7684\u8fd0\u884c\u65f6\u957f\u3002\u5728\u4ee3\u7801\u5757\u5f00\u59cb\u65f6\u8c03\u7528 time.time() \uff0c\u5e76\u5728\u4ee3\u7801\u7ed3\u675f\u65f6\u518d\u6b21\u8c03\u7528\uff0c\u5c31\u53ef\u4ee5\u7528\u7b2c\u4e8c\u4e2a\u65f6\u95f4\u6233\u51cf\u53bb\u7b2c\u4e00\u4e2a\uff0c\u5f97\u5230\u8fd9\u90e8\u5206\u4ee3\u7801\u5757\u7684\u8fd0\u884c\u65f6\u957f\u3002<\/p>\n<div>\n<pre>import time\nlogging.basicConfig(level=logging.DEBUG, format=\\'%(levelname)s - %(message)s\\')\ndef factorial(num):\n    \\'\\'\\'\n    \u8ba1\u7b97\u9636\u4e58\n    :param num:\n    :return:\n    \\'\\'\\'\n    factorial = 1\n    for i in range(1, num + 1):\n        factorial = factorial * i\n    return factorial\nstart_time = time.time()\nresult = factorial(100000)\nend_time = time.time()\nlogging.info(\\'\u8ba1\u7b97\u7ed3\u679c\u6709 %s \u4f4d.\\' % (len(str(result))))\nlogging.info(\\'\u8ba1\u7b97\u8fc7\u7a0b\u5171\u8017\u8d39 %s \u79d2.\\' % (end_time - start_time))\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<pre>INFO - \u8ba1\u7b97\u7ed3\u679c\u6709 456574 \u4f4d.\nINFO - \u8ba1\u7b97\u8fc7\u7a0b\u5171\u8017\u8d39 3.1611809730529785 \u79d2.\n<\/pre>\n<\/div>\n<h2>2 time.sleep() \u51fd\u6570<\/h2>\n<p>\u5982\u679c\u9700\u8981\u8ba9\u7a0b\u5e8f\u6682\u505c\u4e00\u4e0b\uff0c\u53ef\u4ee5\u8c03\u7528 time.sleep()\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u5e0c\u671b\u7a0b\u5e8f\u6682\u505c\u7684\u79d2\u6570\u4f5c\u4e3a\u5165\u53c2\u3002<\/p>\n<div>\n<pre>for i in range(3):\n    logging.info(\\'111\\')\n    time.sleep(0.5)\n    logging.info(\\'222\\')\n    time.sleep(0.5)\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<pre>INFO - 111\nINFO - 222\nINFO - 111\nINFO - 222\nINFO - 111\nINFO - 222\n<\/pre>\n<\/div>\n<p>time.sleep() \u51fd\u6570\u4f1a\u963b\u585e\uff0c\u76f4\u5230\u4f20\u9012\u7ed9 time.sleep() \u7684\u79d2\u6570\u6d41\u901d\u6389\u624d\u4f1a\u7ee7\u7eed\u6267\u884c\u3002\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Python \u5185\u7f6e\u7684 time \u6a21\u5757\u53ef\u4ee5\u8ba9 Python \u7a0b\u5e8f\u8bfb\u53d6\u7cfb\u7edf\u65f6\u949f\u7684\u5f53\u524d\u65f6\u95f4\u3002 1 time.time &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1510\"> <span class=\"screen-reader-text\">Python time \u6a21\u5757<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[106,126],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"Python \u5185\u7f6e\u7684 time \u6a21\u5757\u53ef\u4ee5\u8ba9 Python \u7a0b\u5e8f\u8bfb\u53d6\u7cfb\u7edf\u65f6\u949f\u7684\u5f53\u524d\u65f6\u95f4\u3002 1 time.time&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1510"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1510"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1510\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1510"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}