{"id":2432,"date":"2016-12-02T16:27:20","date_gmt":"2016-12-02T14:27:20","guid":{"rendered":"http:\/\/www.itersdesktop.com\/?p=2432"},"modified":"2016-12-11T23:59:07","modified_gmt":"2016-12-11T21:59:07","slug":"measure-running-time-a-routine-in-python","status":"publish","type":"post","link":"https:\/\/www.itersdesktop.com\/vi\/2016\/12\/02\/measure-running-time-a-routine-in-python\/","title":{"rendered":"T\u00ednh th\u1eddi gian ch\u1ea1y c\u1ee7a m\u1ed9t ch\u01b0\u01a1ng tr\u00ecnh trong Python"},"content":{"rendered":"<p><\/p>\n<p style=\"text-align: justify;\">T\u00f4i ngh\u0129 r\u1eb1ng b\u00e0i vi\u1ebft s\u1ebd gi\u00fap \u00edch cho b\u1ea1n trong vi\u1ec7c t\u00ednh t\u1ed5ng th\u1eddi gian ch\u1ea1y c\u1ee7a m\u1ed9t ch\u01b0\u01a1ng tr\u00ecnh trong Python. Khi ph\u1ea3i x\u1eed l\u00fd kh\u1ed1i m\u1ed9t kh\u1ed1i l\u01b0\u1ee3ng d\u1eef li\u1ec7u l\u1edbn, ch\u01b0\u01a1ng tr\u00ecnh t\u1ed1n kh\u00e1 nhi\u1ec1u th\u1eddi gian. Hi\u1ec3n th\u1ecb th\u1eddi gian ch\u1ea1y, th\u1eddi \u0111i\u1ec3m b\u1eaft \u0111\u1ea7u v\u00e0 k\u1ebft th\u00fac c\u00f3 \u00fd ngh\u0129a trong vi\u1ec7c ghi l\u1ea1i tr\u1ea1ng th\u00e1i v\u00e0 c\u1ea3i ti\u1ebfn ch\u01b0\u01a1ng tr\u00ecnh. D\u0129 nhi\u00ean l\u00e0 c\u00f3 nhi\u1ec1u c\u00e1ch \u0111\u1ec3 l\u00e0m vi\u1ec7c n\u00e0y. V\u1edbi t\u00f4i, \u0111o\u1ea1n code b\u00ean d\u01b0\u1edbi kh\u00e1 \u0111\u01a1n gi\u1ea3n v\u00e0 d\u1ec5 hi\u1ec3u.<\/p>\n<pre class=\"theme:eclipse font:courier-new lang:python decode:true \">import time\r\nfrom time import gmtime, strftime\r\n\r\n# *nix system\r\nstart_time = time.time()\r\n# Windows system\r\n#start_time = time.clock()\r\nprint(\"Started the job on %s\" % strftime(\"%a, %d %b %Y %X +0000\", gmtime()))\r\n\r\n# run all your routines since here\r\nmain()\r\ntest_1()\r\nfinish()\r\n# To demonstrate this script, I try to print 100000 integer numbers\r\nfor i in range(100000):\r\n    print(i)\r\nprint(\"It took %s seconds\" % str(time.time() - start_time))\r\nprint(\"Finished the job on %s\" % strftime(\"%a, %d %b %Y %X +0000\", gmtime()))<\/pre>\n<p><figure id=\"attachment_2434\" aria-describedby=\"caption-attachment-2434\" style=\"width: 545px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2434 size-full\" src=\"http:\/\/www.itersdesktop.com\/wp-content\/uploads\/2016\/12\/Screenshot-1.png\" alt=\"Compute the running time of your program in Python\" width=\"545\" height=\"342\" srcset=\"https:\/\/www.itersdesktop.com\/wp-content\/uploads\/2016\/12\/Screenshot-1.png 545w, https:\/\/www.itersdesktop.com\/wp-content\/uploads\/2016\/12\/Screenshot-1-300x188.png 300w, https:\/\/www.itersdesktop.com\/wp-content\/uploads\/2016\/12\/Screenshot-1-50x31.png 50w\" sizes=\"auto, (max-width: 545px) 100vw, 545px\" \/><figcaption id=\"caption-attachment-2434\" class=\"wp-caption-text\">Compute the running time of your program in Python<\/figcaption><\/figure><\/p>","protected":false},"excerpt":{"rendered":"<p>T\u00f4i ngh\u0129 r\u1eb1ng b\u00e0i vi\u1ebft s\u1ebd gi\u00fap \u00edch cho b\u1ea1n trong vi\u1ec7c t\u00ednh t\u1ed5ng th\u1eddi gian ch\u1ea1y c\u1ee7a m\u1ed9t ch\u01b0\u01a1ng tr\u00ecnh trong Python. Khi ph\u1ea3i x\u1eed l\u00fd kh\u1ed1i m\u1ed9t kh\u1ed1i&hellip; <\/p>\n","protected":false},"author":2,"featured_media":2434,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[122],"tags":[600,601],"class_list":["post-2432","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-estimate-running-time","tag-tinh-thoi-gian-chay-cua-chuong-trinh"],"_links":{"self":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts\/2432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/comments?post=2432"}],"version-history":[{"count":7,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts\/2432\/revisions"}],"predecessor-version":[{"id":2470,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/posts\/2432\/revisions\/2470"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/media\/2434"}],"wp:attachment":[{"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/media?parent=2432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/categories?post=2432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/vi\/wp-json\/wp\/v2\/tags?post=2432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}