{"id":353347,"date":"2024-05-20T22:26:11","date_gmt":"2024-05-20T22:26:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=353347"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=353347","title":{"rendered":"<span>\u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 Python \u2014 \u043f\u043e\u0447\u0435\u043c\u0443 \u0438 \u0433\u0434\u0435 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442 \u0432\u0430\u0448 \u043a\u043e\u0434<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/companies\/ruvds\/articles\/757336\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/el\/s7\/cu\/els7curf_p__dc7uftuc2fwhryy.png\" data-src=\"https:\/\/habrastorage.org\/webt\/el\/s7\/cu\/els7curf_p__dc7uftuc2fwhryy.png\"\/><\/div>\n<p><\/a><br \/>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e: \u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435, \u0443\u0448\u043b\u0438 \u043f\u043e\u043f\u0438\u0442\u044c \u043a\u043e\u0444\u0435, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043f\u044f\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c \u043c\u0438\u043d\u0443\u0442 \u0441\u043f\u0443\u0441\u0442\u044f \u0432\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c, \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u043e\u0441\u044c \u0435\u0434\u0432\u0430 \u043b\u0438 10%.<\/p>\n<p>  \u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u043a\u0440\u0438\u043f\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e? \u041a\u0430\u043a\u0430\u044f \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u044c \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442? \u0414\u0435\u043b\u043e \u0432 \u0447\u0442\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438? \u041a\u0430\u043a \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435? <em>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439?<\/em><\/p>\n<p>  \u041e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u00ab\u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u00bb (profiler).<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2><font color=\"#3AC1EF\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a?<\/font><\/h2>\n<p>  \u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0449\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u043c \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<p>  \u041f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430, \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (\u044d\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00ab\u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c\u00bb \u0438\u043b\u0438 \u00ab\u0431\u0443\u0442\u044b\u043b\u043e\u0447\u043d\u044b\u043c \u0433\u043e\u0440\u043b\u044b\u0448\u043a\u043e\u043c\u00bb, bottleneck), \u0430 \u043c\u043e\u0436\u0435\u0442, \u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c, \u043a\u0430\u043a \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443. \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438 \u0443\u0441\u0442\u0440\u0430\u043d\u044f\u0442\u044c \u0443\u0437\u043a\u0438\u0435 \u043c\u0435\u0441\u0442\u0430 \u2014 \u044d\u0442\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.<\/p>\n<h2><font color=\"#3AC1EF\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/font><\/h2>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b, \u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u043d\u0451\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0430\u0439\u043b \u0441\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u043d\u043e-\u0446\u0438\u0444\u0440\u043e\u0432\u044b\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 (\u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e):<\/p>\n<pre><code class=\"python\">import random import string  def generate_random_string(length):     \"\"\"Generate a random string of lowercase letters and digits.\"\"\"     letters_and_digits = string.ascii_letters + string.digits     return ''.join(random.choice(letters_and_digits) for _ in range(length))  def generate_random_file(filename, num_lines, line_length):     \"\"\"Generate a file of random lines with the given number and length.\"\"\"     with open(filename, 'w') as f:         for i in range(num_lines):             random_line = generate_random_string(line_length) + '\\n'             f.write(random_line)  if __name__ == '__main__':     # \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c 1000000 \u0441\u0442\u0440\u043e\u043a \u043f\u043e 1000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043a\u0430\u0436\u0434\u0430\u044f     generate_random_file('random.txt', 1_000_000, 1000)<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u043d\u0430\u0448\u0443 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u2014 \u043e\u043d\u0430 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0444\u0430\u0439\u043b \u0441\u0442\u0440\u043e\u043a\u0430 \u0437\u0430 \u0441\u0442\u0440\u043e\u043a\u043e\u0439, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 \u0432 \u043d\u0438\u0445 \u0441\u043b\u043e\u0432 <code>bob<\/code> \u0438 <code>rob<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u0435\u0434\u0448\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0446\u0438\u0444\u0440\u0430:<\/p>\n<pre><code class=\"python\">import re  def baseline():     num_total_matches = 0     pattern1 = r\"[0-9]{1}bob\"     pattern2 = r\"[0-9]{1}rob\"          with open('random.txt', 'rt') as f:         for line in f:             line = line.lower()  # \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0432\u0435\u0441\u044c \u0442\u0435\u043a\u0441\u0442 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440             for pattern in [pattern1, pattern2]:                 # \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435                 matches = re.findall(pattern, line)                  # \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439                 num_matches = len(matches)                 num_total_matches += num_matches                  return num_total_matches<\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 <code>abc1robdef02bob<\/code> \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>baseline<\/code>, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 (\u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 10861) \u0438 \u0437\u0430\u043c\u0435\u0440\u044f\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u2014 \u043d\u0430 \u043c\u043e\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c 32 \u0441.<\/p>\n<p>  \u041a\u0430\u043a \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043a\u043e\u0434\u0430?<\/p>\n<h2><font color=\"#3AC1EF\">\u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0446\u0435\u043b\u0438 \u0434\u043b\u044f \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f<\/font><\/h2>\n<p>  \u041a\u043e\u0434 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442\u044c \u0447\u0435\u0442\u044b\u0440\u0435 \u0447\u0430\u0441\u0442\u0438. \u0412\u043e\u0442 \u043e\u043d\u0438:<\/p>\n<ol>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u044b\u0440\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0432\u043c\u0435\u0441\u0442\u043e <a href=\"https:\/\/docs.python.org\/3\/library\/re.html#re-objects\">\u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439<\/a>.<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0451\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/li>\n<li>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"https:\/\/docs.python.org\/3\/library\/re.html#re.I\">\u0444\u043b\u0430\u0433\u0430 \u043d\u0435\u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443<\/a>.<\/li>\n<li>\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e, \u0430 \u043d\u0435 \u043a\u0440\u0443\u043f\u043d\u044b\u043c\u0438 \u0431\u043b\u043e\u043a\u0430\u043c\u0438.<\/li>\n<\/ol>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/fk\/f9\/hz\/fkf9hz3t_puj9jgaytlvgw9x2nw.png\" data-src=\"https:\/\/habrastorage.org\/webt\/fk\/f9\/hz\/fkf9hz3t_puj9jgaytlvgw9x2nw.png\"\/><\/div>\n<p><i><font color=\"#999999\">1) \u041c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u044b\u0440\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b? 2) \u041c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u0432\u043e\u0434-\u0432\u044b\u0432\u043e\u0434? 3) \u041c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440? 4) \u041c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 \u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u043f\u043e\u0438\u0441\u043a?<\/font><\/i><\/p>\n<p>  \u041a\u0430\u043a \u0443\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c? \u041d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a.<\/p>\n<h2><font color=\"#3AC1EF\">\u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438 Python<\/font><\/h2>\n<p>  \u041c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u2014 \u0432\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. \u0412 Python \u0443\u0436\u0435 \u0435\u0441\u0442\u044c <a href=\"https:\/\/docs.python.org\/3\/library\/profile.html\">\u0434\u0432\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a> \u2014 <code>cProfile<\/code> \u0438 <code>profile<\/code>. \u041e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043e\u0434\u043d\u0443 \u0437\u0430\u0434\u0430\u0447\u0443, \u043d\u043e <code>cProfile<\/code> \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 C, \u0430 <code>profile<\/code> \u2014 \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c Python, \u043d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043d\u0435\u0442. \u041c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0432\u0438\u0434\u0435, \u043e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043c \u0441\u0435\u0431\u0435 \u0436\u0438\u0437\u043d\u044c, \u0435\u0441\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<p>  \u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0443\u043d\u043a\u0446\u0438\u0438) \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432 \u0444\u0430\u0439\u043b. \u041c\u043e\u0434\u0443\u043b\u044c \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>profilehooks<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <a href=\"https:\/\/pypi.org\/project\/profilehooks\/\">\u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0443\u044e \u043d\u0430\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">from profilehooks import profile  # stdout=False -> \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b # filename -> \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f @profile(stdout=False, filename='baseline.prof') def baseline():     ...<\/code><\/pre>\n<p>  \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>pip install profilehooks<\/code>.<\/p>\n<p>  \u0418 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u043b\u044f \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u0434\u0432\u0443\u043c\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d SnakeViz \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0431\u044b\u0441\u0442\u0440\u044b\u0439<\/font><\/h3>\n<p>  <a href=\"https:\/\/github.com\/jiffyclub\/snakeviz\">Snakeviz<\/a> \u2014 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Python. \u0415\u0433\u043e \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c (<code>pip install snakeviz<\/code>) \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c (<code>snakeviz &lt;path-to-profiling-output><\/code>). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>baseline<\/code>.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/z_\/ld\/ob\/z_ldobn7sgjm7isjosiyj00ej98.png\" data-src=\"https:\/\/habrastorage.org\/webt\/z_\/ld\/ob\/z_ldobn7sgjm7isjosiyj00ej98.png\"\/><\/div>\n<p><i><font color=\"#999999\">\u0418\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b Snakeviz \u2014 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 <strong><font color=\"#3AC1EF\">icicle<\/font><\/strong> (\u0441\u043b\u0435\u0432\u0430) \u0438 <strong><font color=\"#3AC1EF\">sunburst<\/font><\/strong> (\u043f\u0440\u0430\u0432\u044b\u0439, \u043c\u0435\u043d\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439). \u041c\u043e\u0436\u043d\u043e \u043d\u0430\u0432\u043e\u0434\u0438\u0442\u044c \u043c\u044b\u0448\u044c\u044e \u0438 \u0449\u0451\u043b\u043a\u0430\u0442\u044c \u043d\u0430 \u043b\u044e\u0431\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438. \u0421\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437 \u0438\u0434\u0451\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0430 \u0434\u043b\u0438\u043d\u0430 \u043b\u0438\u043d\u0438\u0438 \u2014 \u044d\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u043e\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u0434\u043e\u043c \u043d\u0430 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435<\/font><\/i><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/or\/tw\/ul\/ortwuljm6iz50xzadtqudqsdw2o.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/or\/tw\/ul\/ortwuljm6iz50xzadtqudqsdw2o.jpeg\" data-blurred=\"true\"\/><\/div>\n<p><i><font color=\"#999999\">\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, Snakeviz \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u043e\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/font><\/i><\/p>\n<p>  \u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>findall<\/code>, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438. \u0417\u043d\u0430\u0447\u0438\u0442, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u043a\u043e\u0434, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0438 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043d\u0430, \u0430 \u043d\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0435.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d gprof2dot \u2014 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0438 \u0433\u0438\u0431\u043a\u0438\u0439<\/font><\/h3>\n<p>  <a href=\"https:\/\/github.com\/jrfonseca\/gprof2dot\">Gprof2dot<\/a> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u0443\u044e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u0432\u0438\u0434\u0435 \u0431\u043b\u043e\u043a-\u0441\u0445\u0435\u043c\u044b, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0444\u0430\u0439\u043b\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043d\u0451\u043c \u043b\u0435\u0433\u043a\u043e \u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 (\u0430 \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e). \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u0435\u043d \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 <a href=\"https:\/\/graphviz.org\/download\/\">Graphviz<\/a>.<\/p>\n<p>  \u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 gprof2dot \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>pip install gprof2dot<\/code>.<\/p>\n<p>  \u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"powershell\">python -m gprof2dot -f pstats &lt;profiling-results-file> | dot -Tpng -o output.png<\/code><\/pre>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u0432\u0438\u0434\u0435 \u0433\u0440\u0430\u0444\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <code>dot<\/code>, \u0430 \u0437\u0430\u0442\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u2014 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430. \u041a\u043e\u043c\u0430\u043d\u0434\u0430 <code>dot<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u0432\u044b\u0432\u043e\u0434\u0430, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 <code>.jpg<\/code> \u0438 <code>.svg<\/code>, \u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b <code>gprof2dot<\/code> \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0433\u0438\u0431\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u043d\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/di\/lb\/kv\/dilbkvlr0hp0dfzixaj6tpqmgn4.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/di\/lb\/kv\/dilbkvlr0hp0dfzixaj6tpqmgn4.jpeg\" data-blurred=\"true\"\/><\/div>\n<p><i><font color=\"#999999\">\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0433\u0440\u0430\u0444\u0430. \u0412 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430\u0445 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u043e\u0431\u0449\u0430\u044f \u0434\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043d\u043d\u0430\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 (%), \u043d\u043e \u0441\u044e\u0434\u0430 \u0432\u043a\u043b\u044e\u0447\u0451\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043a\u043e\u0434\u0435<\/font><\/i><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0439, \u0433\u0440\u0430\u0444 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u043c, \u0447\u0442\u043e \u043f\u043e\u0438\u0441\u043a \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 88% \u043e\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a Graphviz (\u043a\u043e\u043c\u0430\u043d\u0434\u0430 <code>dot<\/code>), \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/pypi.org\/project\/graphviz\/\">\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0430\u043a\u0435\u0442 Python \u0434\u043b\u044f Graphviz<\/a> (<code>pip install graphviz<\/code>), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 Python \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<\/p>\n<ol>\n<li>\u041c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b <code>gprof2dot<\/code> \u0432 \u0444\u0430\u0439\u043b <code>.dot<\/code>:\n<p>  <code>python -m gprof2dot -f pstats file.prof > file.dot<\/code><\/p>\n<\/li>\n<li>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <code>.dot<\/code> \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430:<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"python\">import graphviz      def make_png(input_file_name, output_file_name):     dot = graphviz.Source.from_file(input_file_name)     dot.render(outfile=output_file_name)      if __name__ == '__main__':     make_png('file.dot', 'file.svg')  # \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 .png, .jpg \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/code><\/pre>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430<\/font><\/h2>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u0441\u043a\u043e\u0440\u0438\u043c \u043a\u043e\u0434, \u0441\u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0432 \u0434\u0432\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u043e\u0434\u043d\u043e:<\/p>\n<pre><code class=\"python\">def single_pattern():     num_total_matches = 0     pattern = r\"[0-9][rb]ob\"  # \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u0432\u0443\u0445          with open('random.txt', 'rt') as f:         for line in tqdm(f, total=1_000_000):             line = line.lower()             # \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435             matches = re.findall(pattern, line)              # \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439             num_matches = len(matches)             num_total_matches += num_matches              return num_total_matches<\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c 15 \u0441 \u2014 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0430\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430!<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/ej\/kn\/i6\/ejkni6zvf0jziydertzxz7pas_w.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/ej\/kn\/i6\/ejkni6zvf0jziydertzxz7pas_w.jpeg\" data-blurred=\"true\"\/><\/div>\n<p><i><font color=\"#999999\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e % \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u043c\u043e\u0433\u043e findall \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u043d\u0438\u0437\u0438\u043b\u0441\u044f (88% -> 81.5%)<\/font><\/i><\/p>\n<p>  \u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043b\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0431\u043e\u0440 \u2014 \u0434\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u043c\u043e\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>findall<\/code> \u0441\u043d\u0438\u0437\u0438\u043b\u0430\u0441\u044c, \u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0430\u0441\u044c (\u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430).<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u0442\u0440\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0434\u0435\u0438, \u0430 \u043d\u0435 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0443\u0437\u043a\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0440\u0430\u0432\u043d\u044b\u043c 32 \u0441, \u043a\u0430\u043a \u0438 \u0432 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u043c \u043a\u043e\u0434\u0435! \u041c\u044b \u0431\u044b \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b\u0438 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0443\u0441\u0438\u043b\u0438\u0439, \u043d\u0435 \u0434\u043e\u0431\u0438\u0432\u0448\u0438\u0441\u044c \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439! <em>\u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u0436\u043d\u043e \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0443\u0437\u043a\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445.<\/em><\/p>\n<pre><code class=\"python\">def wasted_efforts():     num_total_matches = 0     # \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f     pattern1 = re.compile(r\"[0-9]{1}rob\", flags=re.IGNORECASE)     # \u0422\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0435\u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443 \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a     pattern2 = re.compile(r\"[0-9]{1}bob\", flags=re.IGNORECASE)          with open('random.txt', 'rt') as f:         # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0431\u043b\u043e\u043a \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u0437\u0430 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0445\u043e\u0434         chunk = []         for line in tqdm(f, total=1_000_000):             chunk.append(line)                          if len(chunk) == 1000:                 chunk_str = ''.join(chunk)                 for pattern in [pattern1, pattern2]:                     # \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435                     matches = re.findall(pattern, chunk_str)                      # \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439                     num_matches = len(matches)                     num_total_matches += num_matches                                      chunk = []      # \u041d\u043e \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043d\u0430\u0448\u0438 \u0443\u0441\u0438\u043b\u0438\u044f, \u043a\u043e\u0434 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439, \u043a\u0430\u043a \u0438 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439     return num_total_matches<\/code><\/pre>\n<p>  <\/p>\n<h3><font color=\"#3AC1EF\">\u258d Multiprocessing<\/font><\/h3>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>findall<\/code> \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0435\u0451 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0432\u0435\u0449\u044c: \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u0434.<\/p>\n<p>  \u0421\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u0432 \u043d\u0438\u0445 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e. \u041a\u0430\u043a \u043d\u0430\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<p>  \u041f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c <a href=\"https:\/\/docs.python.org\/3\/library\/multiprocessing.html#multiprocessing.pool.Pool\">Process Pool<\/a> \u2014 \u043e\u0431\u044a\u0435\u043a\u0442, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 Python, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u0430\u044f \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437 \u043d\u0438\u0445, \u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043f\u0443\u043b\u0430 <code>map<\/code>, \u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"python\">from multiprocessing import Pool   def calc_num_matches(string):     # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Pool     # \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0444\u0430\u0439\u043b\u0435     pattern = r\"[0-9]{1}[rb]ob\"     return len(re.findall(pattern, string))  def chunks_single_pool():     num_total_matches = 0          pool = Pool(8)  # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c &lt;= \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044f\u0434\u0435\u0440 \u0432\u0430\u0448\u0435\u0433\u043e CPU          with open('random.txt', 'rt') as f:         chunk = []         # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a         for line in tqdm(f, total=1_000_000):             line = line.lower()             chunk.append(line)                          if len(chunk) == 1000:                 # \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e `calc_num_matches`                 num_ind_matches = pool.map(calc_num_matches, chunk)                 # \u0418 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f                 num_matches = sum(num_ind_matches)                 num_total_matches += num_matches                  chunk = []          return num_total_matches<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c\u2026 6,1 \u0441! \u042d\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u043a\u043e\u0440\u0434. \u0412 2,2 \u0440\u0430\u0437\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 5 \u0440\u0430\u0437 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/kk\/me\/os\/kkmeosz-thhx4cxptgqpzzice7w.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/kk\/me\/os\/kkmeosz-thhx4cxptgqpzzice7w.jpeg\" data-blurred=\"true\"\/><\/div>\n<p><i><font color=\"#999999\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u043e\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u043e\u043b\u044f regex-\u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c\u0441\u044f (\u0437\u0435\u043b\u0451\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438)<\/font><\/i><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/zu\/s4\/vq\/zus4vqocbmfqvv5mluw_1pf7asm.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/zu\/s4\/vq\/zus4vqocbmfqvv5mluw_1pf7asm.jpeg\" data-blurred=\"true\"\/><\/div>\n<p><i><font color=\"#999999\">Snakeviz \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0442\u0443 \u0436\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u0443<\/font><\/i><\/p>\n<p>  \u041e\u0431\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e regex-\u043f\u043e\u0438\u0441\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 2\/3 \u043e\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u2014 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<h2><font color=\"#3AC1EF\">\u0422\u043e\u043d\u043a\u043e\u0441\u0442\u0438<\/font><\/h2>\n<p>  <\/p>\n<h3><font color=\"#3AC1EF\">\u258d Multiprocessing<\/font><\/h3>\n<p>  \u0412\u0430\u0436\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 regex-\u043f\u043e\u0438\u0441\u043a. \u041e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u0440\u0430\u0447\u0435\u043d\u043e 4 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u043e \u043e\u043d \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u043c\u0443 \u0432 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445 \u043a\u043e\u0434\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438, \u043f\u043e \u0441\u0443\u0442\u0438, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438, \u0441\u043b\u0430\u0431\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043d\u0430\u0448\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c Python.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0439 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438\/\u043a\u043e\u0434\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>@profile<\/code>.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d Multithreading<\/font><\/h3>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430 Python, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e <a href=\"https:\/\/realpython.com\/python-gil\/\">Global Interpreter Lock (GIL)<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430 \u0440\u0430\u0437 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u043a\u043e\u0434\u0430 \u043d\u0430 Python (\u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 Python).<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u043d\u0435 \u0434\u043b\u044f Python (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, NumPy, PyTorch, scipy) \u0438\u043b\u0438 \u0441 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0432\u0432\u043e\u0434\u043e\u043c-\u0432\u044b\u0432\u043e\u0434\u043e\u043c (\u0432\u0435\u0431-\u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0438), \u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430 Python \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430 C, C++, Fortran \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  \u0412 \u044d\u0442\u0438\u0445 \u0434\u0432\u0443\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043e\u0431\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Python \u2014 <a href=\"https:\/\/docs.python.org\/3\/library\/profile.html#module-cProfile\">profile \u0438 cProfile<\/a> \u2014 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0438, \u0438\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <a href=\"https:\/\/github.com\/sumerc\/yappi\">Yappi<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/github.com\/gaogaotiantian\/viztracer\">VizTracer<\/a>.<\/p>\n<h2><font color=\"#3AC1EF\">\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432 GPU<\/font><\/h2>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 GPU, \u0442\u043e \u0443\u0447\u0442\u0438\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0441 CPU. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 \u0432 GPU \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0441 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0432\u0435\u0434\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u043d\u0430 Python \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 GPU. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0438 \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430 GPU \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">import torch from profilehooks import profile  @profile(filename='gpu_test.prof', stdout=False) def compute_big_sum(tensor: torch.Tensor):     # \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e     a = tensor.sum()     b = tensor.pow(2).sum()     c = tensor.sqrt().sum()          sum_all = a + b + c     sum_all_cpu = sum_all.cpu()  # \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c CPU          # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 (\u0441\u043a\u0430\u043b\u044f\u0440\u043d\u0443\u044e)     return sum_all_cpu      if __name__ == '__main__':     # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0443\u044e\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 GPU     X = torch.rand((10000, 10000), dtype=torch.float64, device='cuda:0')     res = compute_big_sum(X)          print(float(res))<\/code><\/pre>\n<p>  \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 10000&#215;10000 \u043d\u0430 PyTorch (\u0432 GPU), \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0443\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ol>\n<li>\u0421\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/li>\n<li>\u0421\u0443\u043c\u043c\u0443 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/li>\n<li>\u0421\u0443\u043c\u043c\u0443 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 \u043a\u043e\u0440\u043d\u0435\u0439 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/li>\n<li>\u0421\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0443\u043c\u043c.<\/li>\n<\/ol>\n<p>  \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e.<\/p>\n<p>  <i>\u041a\u0430\u043a \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435, \u043a\u0430\u043a\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043a\u043e\u0434\u0430 \u0437\u0430\u0439\u043c\u0451\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438?<\/i><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/fr\/g7\/fu\/frg7fussjhkha_rahf7wbyvssr8.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/fr\/g7\/fu\/frg7fussjhkha_rahf7wbyvssr8.jpeg\" data-blurred=\"true\"\/><\/div>\n<p><i><font color=\"#999999\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong><font color=\"#3AC1EF\">compute_big_sum<\/font><\/strong><\/font><\/i><\/p>\n<p>  \u041a\u0430\u043a \u043d\u0438 \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 <code>.cpu()<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0449\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438 GPU \u0432 \u043f\u0430\u043c\u044f\u0442\u044c CPU! \u041d\u043e \u044d\u0442\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430. \u041c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432\u0441\u0435\u0433\u043e 8 \u0431\u0430\u0439\u0442\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445! \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0430\u044f?<\/p>\n<p>  \u041d\u0435\u0442.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u043d\u0443\u0442\u0440\u0438 PyTorch \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f <a href=\"https:\/\/www.turing.com\/kb\/understanding-nvidia-cuda\">CUDA<\/a> \u0432 GPU, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043e\u0442 CPU \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c, \u0442\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <code>.sum()<\/code> \u0438\u043b\u0438 <code>torch.pow()<\/code>. Python \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 GPU \u043d\u0430\u0447\u0430\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043d\u043e \u043d\u0435 \u0436\u0434\u0451\u0442, \u043f\u043e\u043a\u0430 \u043e\u043d\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0430\u0442\u0441\u044f! \u0422\u043e \u0435\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 Python \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<p>  \u041e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>.cpu()<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0449\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438 GPU \u0432 \u043f\u0430\u043c\u044f\u0442\u044c CPU. \u041e\u043d \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u043e\u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 GPU, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u043a \u043d\u0430\u0448\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435.<\/p>\n<p>  \u041d\u043e \u043a\u0430\u043a \u043d\u0430\u043c \u044d\u0442\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c?<\/p>\n<ol>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/pytorch.org\/tutorials\/recipes\/recipes\/profiler_recipe.html\">\u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a PyTorch<\/a>, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0432\u0430\u0441 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u0430\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432 GPU (\u0438\u043b\u0438 \u043e\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430), \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u0434 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0441\u0435\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0432 GPU <code>torch.cuda.synchronize()<\/code>, \u0447\u0442\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 PyTorch \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432 GPU.<\/li>\n<\/ol>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/sh\/i9\/uc\/shi9ucm4lpyof-rgngebaqlulmo.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/sh\/i9\/uc\/shi9ucm4lpyof-rgngebaqlulmo.jpeg\" data-blurred=\"true\"\/><\/div>\n<p><i><font color=\"#999999\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>torch.cuda.synchronize()<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c <code>.cpu()<\/code> \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 1% \u043e\u0431\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0430 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0451 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0432 GPU, \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c<\/font><\/i><\/p>\n<p>  \u041a\u043e\u0434 \u043d\u0430\u0448\u0435\u0439 \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>compute_big_sum<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">def compute_big_sum(tensor: torch.Tensor):     a = tensor.sum()     b = tensor.pow(2).sum()     c = tensor.sqrt().sum()          sum_all = a + b + c     torch.cuda.synchronize()  # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 GPU                                # \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u0438     sum_all_cpu = sum_all.cpu()          return sum_all_cpu<\/code><\/pre>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">\u0421\u0441\u044b\u043b\u043a\u0438<\/font><\/h2>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/docs.python.org\/3\/library\/re.html\">\u0421\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u043e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c Python<\/a>.<\/li>\n<li><a href=\"https:\/\/docs.python.org\/3\/library\/profile.html\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u0432 Python<\/a>.<\/li>\n<li><a href=\"https:\/\/pypi.org\/project\/profilehooks\/\">Profilehooks \u2014 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0435\u0439 \u043a\u043e\u0434\u0430<\/a>.<\/li>\n<li><a href=\"https:\/\/github.com\/jiffyclub\/snakeviz\">Snakeviz \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a>.<\/li>\n<li><a href=\"https:\/\/github.com\/jrfonseca\/gprof2dot\">Gprof2dot \u2014 \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0438 \u0433\u0438\u0431\u043a\u0438\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/a>.<\/li>\n<li><a href=\"https:\/\/graphviz.org\/download\/\">GraphViz \u2014 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 gprof2dot \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0433\u0440\u0430\u0444\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/a>.<\/li>\n<li><a href=\"https:\/\/pypi.org\/project\/graphviz\/\">Graphviz \u2014 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 Python \u0434\u043b\u044f GraphViz<\/a>.<\/li>\n<li><a href=\"https:\/\/docs.python.org\/3\/library\/multiprocessing.html\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e multiprocessing \u0432 Python<\/a>.<\/li>\n<li><a href=\"https:\/\/realpython.com\/python-gil\/\">\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 Global Interpreter Lock (GIL) Python<\/a>.<\/li>\n<li><a href=\"https:\/\/github.com\/sumerc\/yappi\">Yappi: \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a Python \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0445 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432<\/a>.<\/li>\n<li><a href=\"https:\/\/github.com\/gaogaotiantian\/viztracer\">VizTracer: \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a Python \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0445 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432<\/a>.<\/li>\n<li><a href=\"https:\/\/www.turing.com\/kb\/understanding-nvidia-cuda\">\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 CUDA<\/a>.<\/li>\n<\/ol>\n<p>  <\/p>\n<blockquote><p><b><font color=\"#3AC1EF\"><a href=\"https:\/\/t.me\/ruvds_community\">Telegram-\u043a\u0430\u043d\u0430\u043b \u0441 \u0440\u043e\u0437\u044b\u0433\u0440\u044b\u0448\u0430\u043c\u0438 \u043f\u0440\u0438\u0437\u043e\u0432, \u043d\u043e\u0432\u043e\u0441\u0442\u044f\u043c\u0438 IT \u0438 \u043f\u043e\u0441\u0442\u0430\u043c\u0438 \u043e \u0440\u0435\u0442\u0440\u043e\u0438\u0433\u0440\u0430\u0445 ?\ufe0f<\/a><\/font><\/b><\/p><\/blockquote>\n<p><a href=\"http:\/\/ruvds.com\/ru-rub?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=ru_vds&amp;utm_content=profilirovanie_python_pochemu_i_gde_tormozit_vash_kod\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/_p\/_h\/lv\/_p_hlvd2tv0cv9tny8tdytzfhje.png\" data-src=\"https:\/\/habrastorage.org\/webt\/_p\/_h\/lv\/_p_hlvd2tv0cv9tny8tdytzfhje.png\"\/><\/a><\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/757336\/\"> https:\/\/habr.com\/ru\/articles\/757336\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/companies\/ruvds\/articles\/757336\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/el\/s7\/cu\/els7curf_p__dc7uftuc2fwhryy.png\" data-src=\"https:\/\/habrastorage.org\/webt\/el\/s7\/cu\/els7curf_p__dc7uftuc2fwhryy.png\"\/><\/div>\n<p><\/a><br \/>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e: \u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043d\u043e\u0443\u0442\u0431\u0443\u043a\u0435, \u0443\u0448\u043b\u0438 \u043f\u043e\u043f\u0438\u0442\u044c \u043a\u043e\u0444\u0435, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043f\u044f\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c \u043c\u0438\u043d\u0443\u0442 \u0441\u043f\u0443\u0441\u0442\u044f \u0432\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c, \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u043e\u0441\u044c \u0435\u0434\u0432\u0430 \u043b\u0438 10%.<\/p>\n<p>  \u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u043a\u0440\u0438\u043f\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e? \u041a\u0430\u043a\u0430\u044f \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u044c \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442? \u0414\u0435\u043b\u043e \u0432 \u0447\u0442\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438? \u041a\u0430\u043a \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435? <em>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u0441\u043a\u0440\u0438\u043f\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439?<\/em><\/p>\n<p>  \u041e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u00ab\u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u00bb (profiler).  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-353347","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/353347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=353347"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/353347\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=353347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=353347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=353347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}