{"id":770,"date":"2008-06-10T23:56:44","date_gmt":"2008-06-10T14:56:44","guid":{"rendered":"http:\/\/terzeron.com\/?p=770"},"modified":"2008-06-10T23:56:44","modified_gmt":"2008-06-10T14:56:44","slug":"python-profiling-%ec%98%88%ec%a0%9c","status":"publish","type":"post","link":"https:\/\/terzeron.com\/?p=770","title":{"rendered":"Python profiling \uc608\uc81c"},"content":{"rendered":"<p>\ub2e4\uc74c\uc758 \uc608\uc81c\ub294 python\uc5d0 \uae30\ubcf8 \ub0b4\uc7a5\ub41c \ud504\ub85c\ud30c\uc77c\ub7ec(profiler)\uc778 hotshot\uc744 \uc774\uc6a9\ud558\uc5ec GNU prof\uc640 \ube44\uc2b7\ud558\uac8c \ud504\ub85c\ud30c\uc77c\ub9c1\ud558\ub294 \uac83\uc744 \uc2dc\uc5f0\ud574 \ubcf8 \uac83\uc774\ub2e4.<\/p>\n<pre class=\"brush: python\">#!\/usr\/bin\/env python\n# -*- coding: utf-8 -*-\n# vim: set fileencoding=utf-8 :\n\nimport hotshot, hotshot.stats\n\ndef test_func2(i):\nresult = i * 10\nreturn result\n\ndef test_func1(i):\ntest_func2(i)\nresult = 1 * i\nreturn result\n\nprofile_filename = \"prof.result\"\nprof = hotshot.Profile(profile_filename)\nprof.start()\n\nsum = 0\nfor i in range(10000):\nsum = sum + i\ntest_func1(i)\nprint sum\n\nprof.stop()\nprof.close()\nstats = hotshot.stats.load(profile_filename)\nstats.strip_dirs()\nstats.sort_stats('time', 'calls')\nstats.print_stats()<\/pre>\n<p>\uc774 \uc2a4\ud06c\ub9bd\ud2b8\uc758 \uc2e4\ud589 \uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<blockquote><p>49995000<br \/>\n20000 function calls in 0.012 CPU seconds<\/p>\n<p>Ordered by: internal time, call count<\/p>\n<p>ncalls tottime percall cumtime percall filename:lineno(function)<br \/>\n10000 0.008 0.000 0.012 0.000 profile_example.py:11(test_func1)<br \/>\n10000 0.004 0.000 0.004 0.000 profile_example.py:7(test_func2)<br \/>\n0 0.000 0.000 profile:0(profiler)<\/p><\/blockquote>\n<p>\uccab\ubc88\uc9f8 \uc904\uc740 \uc2a4\ud06c\ub9bd\ud2b8\uac00 \uc218\ud589\ud55c \uacb0\uacfc\uc778 1\ubd80\ud130 10000\uae4c\uc9c0\uc758 \ud569\uc744 \uacc4\uc0b0\ud55c \uac83\uc774\ub2e4. \ub098\uba38\uc9c0 \ubd80\ubd84\uc774 \ud504\ub85c\ud30c\uc77c\ub7ec\uac00 \ucd9c\ub825\ud55c \ud1b5\uacc4\uce58\uc778\ub370 \ub2e4\uc74c\uacfc \uac19\uc774 \ud574\uc11d\ud560 \uc218 \uc788\ub2e4.<\/p>\n<p>1) \ucd1d 2\ub9cc \uac1c\uc758 \ud568\uc218 \ud638\ucd9c\uc774 \uc788\uc5c8\uace0, 0.012 \ucd08\uac00 \uc18c\uc694\ub418\uc5c8\ub2e4.<br \/>\n2) \uc218\ud589 \uc2dc\uac04\uacfc \ud638\ucd9c \ud69f\uc218\ub97c \uae30\uc900\uc73c\ub85c \uc815\ub82c\ub418\uc5c8\ub2e4.<br \/>\n3) profile_example.py\uc758 test_func1() \ud568\uc218\ub294 1\ub9cc \ubc88 \ud638\ucd9c\ub418\uc5c8\uace0 \ucd1d \uc218\ud589 \uc2dc\uac04\uc740 0.008\ucd08\uc778\ub370, \ud55c \ubc88 \ud638\ucd9c\uc740 0.008\/10000=0.000\ucd08\uc774\ub2e4. test_func1()\uc774 \ud638\ucd9c\ud55c \ud558\uc704 \ud568\uc218\ub4e4\uae4c\uc9c0 \ud3ec\ud568\ud55c \ub204\uc801 \uc218\ud589 \uc2dc\uac04\uc740 0.012\ucd08\uc774\ub2e4.<br \/>\n4) \uac19\uc740 \uc2a4\ud06c\ub9bd\ud2b8\uc758 test_func2() \ud568\uc218\ub294 1\ub9cc \ubc88 \ud638\ucd9c\ub418\uc5c8\uace0 \ucd1d \uc218\ud589 \uc2dc\uac04\uc740 0.004\ucd08\uc778\ub370, \ud558\uc704 \ud568\uc218\ub4e4\uae4c\uc9c0 \ud3ec\ud568\ud55c \ub204\uc801 \uc218\ud589 \uc2dc\uac04\uc740 0.004\ucd08\uc774\ub2e4.<\/p>\n<div class=\"fb-background-color\">\n\t\t\t  <div \n\t\t\t  \tclass = \"fb-comments\" \n\t\t\t  \tdata-href = \"https:\/\/terzeron.com\/?p=770\"\n\t\t\t  \tdata-numposts = \"100\"\n\t\t\t  \tdata-lazy = \"true\"\n\t\t\t\tdata-colorscheme = \"light\"\n\t\t\t\tdata-order-by = \"time\"\n\t\t\t\tdata-mobile=true>\n\t\t\t  <\/div><\/div>\n\t\t  <style>\n\t\t    .fb-background-color {\n\t\t\t\tbackground: #ffffff !important;\n\t\t\t}\n\t\t\t.fb_iframe_widget_fluid_desktop iframe {\n\t\t\t    width: 100% !important;\n\t\t\t}\n\t\t  <\/style>\n\t\t  ","protected":false},"excerpt":{"rendered":"<p>\ub2e4\uc74c\uc758 \uc608\uc81c\ub294 python\uc5d0 \uae30\ubcf8 \ub0b4\uc7a5\ub41c \ud504\ub85c\ud30c\uc77c\ub7ec(profiler)\uc778 hotshot\uc744 \uc774\uc6a9\ud558\uc5ec GNU prof\uc640 \ube44\uc2b7\ud558\uac8c \ud504\ub85c\ud30c\uc77c\ub9c1\ud558\ub294 \uac83\uc744 \uc2dc\uc5f0\ud574 \ubcf8 \uac83\uc774\ub2e4. #!\/usr\/bin\/env python # -*- coding: utf-8 -*- # vim: set fileencoding=utf-8 : import hotshot, hotshot.stats def test_func2(i): result = i * 10 return result &hellip; <a href=\"https:\/\/terzeron.com\/?p=770\">\uacc4\uc18d \uc77d\uae30 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_sitemap_exclude":false,"_sitemap_priority":"","_sitemap_frequency":"","footnotes":""},"categories":[13],"tags":[],"class_list":["post-770","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/posts\/770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=770"}],"version-history":[{"count":0,"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/posts\/770\/revisions"}],"wp:attachment":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}