{"id":64257,"date":"2026-01-23T05:48:18","date_gmt":"2026-01-22T21:48:18","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/64257.html"},"modified":"2026-01-23T05:48:18","modified_gmt":"2026-01-22T21:48:18","slug":"%e7%ac%ac%e5%8d%81%e4%b8%89%e7%ab%a0-%e6%80%a7%e8%83%bd%e6%84%8f%e8%af%86%e5%85%a5%e9%97%a8%ef%bc%9a%e4%bd%a0%e4%bb%a3%e7%a0%81%e6%85%a2%e5%9c%a8%e5%93%aa%ef%bc%9fprofiling-%e7%9a%84%e5%b7%a5%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/64257.html","title":{"rendered":"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8\uff1a\u4f60\u4ee3\u7801\u6162\u5728\u54ea\uff1fprofiling \u7684\u5de5\u7a0b\u5316\u601d\u8def"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260122214816-69729b204915b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/p>\n<h4>\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8&#xff1a;\u4f60\u4ee3\u7801\u6162\u5728\u54ea&#xff1f;profiling \u7684\u5de5\u7a0b\u5316\u601d\u8def<\/h4>\n<ul>\n<li>\n<ul>\n<li>0. \u672c\u7ae0\u76ee\u6807\u4e0e\u9002\u7528\u573a\u666f<\/li>\n<li>1. \u6027\u80fd\u4f18\u5316\u7684\u5e95\u5c42\u903b\u8f91&#xff1a;\u5148\u5ea6\u91cf&#xff0c;\u518d\u4f18\u5316<\/li>\n<li>2. \u4e09\u7c7b\u74f6\u9888&#xff1a;CPU \/ IO \/ \u5185\u5b58&#xff08;\u5148\u505a\u5206\u7c7b&#xff09;<\/li>\n<li>\n<ul>\n<li>2.1 \u5feb\u901f\u5224\u65ad&#xff1a;\u770b\u73b0\u8c61<\/li>\n<\/ul>\n<\/li>\n<li>3. \u6700\u5c0f profiling \u5de5\u5177\u94fe&#xff08;\u591f\u7528\u5c31\u884c&#xff09;<\/li>\n<li>\n<ul>\n<li>3.1 \u5148\u7528\u6700\u6734\u7d20\u7684 &#096;time&#096;<\/li>\n<li>3.2 &#096;cProfile&#096;&#xff1a;\u627e\u51fd\u6570\u7ea7\u70ed\u70b9&#xff08;CPU&#xff09;<\/li>\n<li>3.3 &#096;line_profiler&#096;&#xff1a;\u7cbe\u786e\u5230\u884c&#xff08;\u5b9a\u4f4d\u201c\u90a3\u4e00\u884c\u201d&#xff09;<\/li>\n<li>3.4 &#096;memory_profiler&#096;&#xff1a;\u770b\u5185\u5b58\u5cf0\u503c&#xff08;\u7206\u5185\u5b58\u5fc5\u5907&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>4. \u6570\u636e\/AI\u5de5\u7a0b\u6700\u5e38\u89c1\u7684\u6027\u80fd\u5751&#xff08;\u9ad8\u9891\u6e05\u5355&#xff09;<\/li>\n<li>\n<ul>\n<li>4.1 Pandas \u7684 &#096;apply&#096;&#xff1a;\u6700\u7ecf\u5178\u7684\u6027\u80fd\u9677\u9631<\/li>\n<li>4.2 &#096;groupby&#096; &#043; &#096;transform&#096; \/ &#096;merge&#096;&#xff1a;\u9690\u6027\u5927\u6740\u5668<\/li>\n<li>4.3 Python \u5faa\u73af\u5904\u7406\u5927\u6570\u7ec4&#xff1a;\u7b97\u6cd5\u590d\u6742\u5ea6\u4e0d\u53d8&#xff0c;\u518d\u5feb\u4e5f\u6ca1\u7528<\/li>\n<li>4.4 IO&#xff1a;\u8bfb CSV \u6bd4\u8bfb Parquet \u6162\u5f97\u591a<\/li>\n<\/ul>\n<\/li>\n<li>5. \u4e00\u4e2a\u53ef\u843d\u5730\u7684 profiling \u6846\u67b6&#xff1a;\u628a\u6027\u80fd\u5f53\u6210\u56de\u5f52\u6d4b\u8bd5<\/li>\n<li>\n<ul>\n<li>5.1 \u57fa\u7ebf\u4e0e\u5bf9\u6bd4&#xff1a;\u56fa\u5b9a\u8f93\u5165 &#043; \u56fa\u5b9a\u6307\u6807<\/li>\n<\/ul>\n<\/li>\n<li>6. \u4f18\u5316\u7b56\u7565\u7684\u4f18\u5148\u7ea7&#xff1a;\u5148\u505a\u201c\u6536\u76ca\u6700\u5927\u201d\u7684<\/li>\n<li>7. \u5c0f\u7ed3&#xff1a;\u6027\u80fd\u610f\u8bc6&#061;\u53ef\u89e3\u91ca\u3001\u53ef\u590d\u73b0\u3001\u53ef\u6301\u7eed<\/li>\n<li>\u4f60\u53ef\u4ee5\u76f4\u63a5\u62ff\u6765\u7528\u7684\u884c\u52a8\u6e05\u5355<\/li>\n<li>\u4e0b\u4e00\u7ae0&#xff1a;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4f60\u6709\u6ca1\u6709\u8fd9\u79cd\u4f53\u9a8c&#xff1a;<\/p>\n<ul>\n<li>\u540c\u6837\u4e00\u6bb5\u6570\u636e\u5904\u7406\u811a\u672c&#xff0c;\u5728\u4f60\u7535\u8111\u4e0a 2 \u5206\u949f&#xff0c;\u5230\u4e86\u670d\u52a1\u5668\u4e0a 30 \u5206\u949f&#xff1b;<\/li>\n<li>\u660e\u660e\u201c\u53ea\u662f\u591a\u52a0\u4e86\u4e00\u4e2a\u7279\u5f81\u201d&#xff0c;\u8bad\u7ec3\u65f6\u95f4\u7ffb\u500d&#xff1b;<\/li>\n<li>\u4f60\u4ee5\u4e3a\u74f6\u9888\u5728\u6a21\u578b&#xff0c;\u7ed3\u679c\u6162\u5728 groupby\u3001\u6162\u5728 IO\u3001\u6162\u5728\u4e00\u4e2a\u4e0d\u7ecf\u610f\u7684 apply\u3002<\/li>\n<\/ul>\n<p>\u6570\u636e\u5206\u6790\u4e0e AI \u5de5\u7a0b\u91cc&#xff0c;\u6027\u80fd\u95ee\u9898\u5f80\u5f80\u4e0d\u662f\u201c\u5199\u5f97\u4e0d\u591f\u5feb\u201d&#xff0c;\u800c\u662f\u6ca1\u6709\u6027\u80fd\u610f\u8bc6&#xff1a; \u4f60\u4e0d\u77e5\u9053\u65f6\u95f4\u82b1\u5728\u54ea\u91cc&#xff0c;\u4e8e\u662f\u4f60\u53ea\u80fd\u9760\u731c\u3002<\/p>\n<p>\u672c\u7ae0\u76ee\u6807\u5f88\u660e\u786e&#xff1a; \u5efa\u7acb\u4e00\u5957 profiling \u7684\u601d\u7ef4\u6846\u67b6&#xff0c;\u8ba9\u4f60\u6bcf\u6b21\u9047\u5230\u201c\u53d8\u6162\u201d&#xff0c;\u90fd\u80fd\u5feb\u901f\u5b9a\u4f4d&#xff1a;\u6162\u5728 CPU&#xff1f;\u6162\u5728 IO&#xff1f;\u6162\u5728\u5185\u5b58&#xff1f;\u6162\u5728\u7b97\u6cd5\u590d\u6742\u5ea6&#xff1f;\u6162\u5728\u6570\u636e\u7ed3\u6784&#xff1f;<\/p>\n<hr \/>\n<h3>0. \u672c\u7ae0\u76ee\u6807\u4e0e\u9002\u7528\u573a\u666f<\/h3>\n<p>\u5b66\u5b8c\u4f60\u5e94\u8be5\u80fd\u505a\u5230&#xff1a;<\/p>\n<li>\u80fd\u7528 30 \u79d2\u5224\u65ad&#xff1a;CPU-bound \/ IO-bound \/ Memory-bound<\/li>\n<li>\u4f1a\u7528\u6700\u5c0f\u5de5\u5177\u94fe&#xff1a;time\u3001cProfile\u3001line_profiler\u3001memory_profiler<\/li>\n<li>\u77e5\u9053\u6570\u636e\u5de5\u7a0b\u6700\u5e38\u89c1\u7684\u201c\u6027\u80fd\u5751\u201d\u5728\u54ea\u91cc&#xff08;Pandas \/ Python \u539f\u751f \/ \u5e8f\u5217\u5316&#xff09;<\/li>\n<li>\u80fd\u628a\u4f18\u5316\u8fc7\u7a0b\u53d8\u6210\u201c\u53ef\u590d\u73b0\u5b9e\u9a8c\u201d&#xff1a;\u57fa\u7ebf \u2192 \u8bc1\u636e \u2192 \u4f18\u5316 \u2192 \u56de\u5f52<\/li>\n<li>\u521d\u6b65\u638c\u63e1\u201c\u6027\u80fd\u9884\u7b97\u201d\u7684\u5199\u6cd5&#xff1a;\u8ba9\u9879\u76ee\u53ef\u957f\u671f\u6269\u5c55<\/li>\n<hr \/>\n<h3>1. \u6027\u80fd\u4f18\u5316\u7684\u5e95\u5c42\u903b\u8f91&#xff1a;\u5148\u5ea6\u91cf&#xff0c;\u518d\u4f18\u5316<\/h3>\n<p>\u5982\u679c\u53ea\u8bb0\u4e00\u53e5\u8bdd&#xff1a;<\/p>\n<p>Never optimize what you haven\u2019t measured.<\/p>\n<p>\u4f60\u9700\u8981\u628a\u6027\u80fd\u95ee\u9898\u5f53\u6210\u4e00\u4e2a\u5b9e\u9a8c\u95ee\u9898&#xff1a;<\/p>\n<p>  #mermaid-svg-57Ex7krZzG6ecLW0{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-57Ex7krZzG6ecLW0 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-57Ex7krZzG6ecLW0 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-57Ex7krZzG6ecLW0 .error-icon{fill:#552222;}#mermaid-svg-57Ex7krZzG6ecLW0 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-57Ex7krZzG6ecLW0 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-57Ex7krZzG6ecLW0 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-57Ex7krZzG6ecLW0 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-57Ex7krZzG6ecLW0 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-57Ex7krZzG6ecLW0 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-57Ex7krZzG6ecLW0 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-57Ex7krZzG6ecLW0 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-57Ex7krZzG6ecLW0 .marker.cross{stroke:#333333;}#mermaid-svg-57Ex7krZzG6ecLW0 svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-57Ex7krZzG6ecLW0 p{margin:0;}#mermaid-svg-57Ex7krZzG6ecLW0 .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-57Ex7krZzG6ecLW0 .cluster-label text{fill:#333;}#mermaid-svg-57Ex7krZzG6ecLW0 .cluster-label span{color:#333;}#mermaid-svg-57Ex7krZzG6ecLW0 .cluster-label span p{background-color:transparent;}#mermaid-svg-57Ex7krZzG6ecLW0 .label text,#mermaid-svg-57Ex7krZzG6ecLW0 span{fill:#333;color:#333;}#mermaid-svg-57Ex7krZzG6ecLW0 .node rect,#mermaid-svg-57Ex7krZzG6ecLW0 .node circle,#mermaid-svg-57Ex7krZzG6ecLW0 .node ellipse,#mermaid-svg-57Ex7krZzG6ecLW0 .node polygon,#mermaid-svg-57Ex7krZzG6ecLW0 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-57Ex7krZzG6ecLW0 .rough-node .label text,#mermaid-svg-57Ex7krZzG6ecLW0 .node .label text,#mermaid-svg-57Ex7krZzG6ecLW0 .image-shape .label,#mermaid-svg-57Ex7krZzG6ecLW0 .icon-shape .label{text-anchor:middle;}#mermaid-svg-57Ex7krZzG6ecLW0 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-57Ex7krZzG6ecLW0 .rough-node .label,#mermaid-svg-57Ex7krZzG6ecLW0 .node .label,#mermaid-svg-57Ex7krZzG6ecLW0 .image-shape .label,#mermaid-svg-57Ex7krZzG6ecLW0 .icon-shape .label{text-align:center;}#mermaid-svg-57Ex7krZzG6ecLW0 .node.clickable{cursor:pointer;}#mermaid-svg-57Ex7krZzG6ecLW0 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-57Ex7krZzG6ecLW0 .arrowheadPath{fill:#333333;}#mermaid-svg-57Ex7krZzG6ecLW0 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-57Ex7krZzG6ecLW0 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-57Ex7krZzG6ecLW0 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-57Ex7krZzG6ecLW0 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-57Ex7krZzG6ecLW0 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-57Ex7krZzG6ecLW0 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-57Ex7krZzG6ecLW0 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-57Ex7krZzG6ecLW0 .cluster text{fill:#333;}#mermaid-svg-57Ex7krZzG6ecLW0 .cluster span{color:#333;}#mermaid-svg-57Ex7krZzG6ecLW0 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-57Ex7krZzG6ecLW0 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-57Ex7krZzG6ecLW0 rect.text{fill:none;stroke-width:0;}#mermaid-svg-57Ex7krZzG6ecLW0 .icon-shape,#mermaid-svg-57Ex7krZzG6ecLW0 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-57Ex7krZzG6ecLW0 .icon-shape p,#mermaid-svg-57Ex7krZzG6ecLW0 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-57Ex7krZzG6ecLW0 .icon-shape rect,#mermaid-svg-57Ex7krZzG6ecLW0 .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-57Ex7krZzG6ecLW0 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-57Ex7krZzG6ecLW0 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-57Ex7krZzG6ecLW0 :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u73b0\u8c61&#xff1a;\u53d8\u6162\/\u8d85\u65f6\/\u7206\u5185\u5b58<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u5b9a\u4e49\u6307\u6807&#xff1a;\u8017\u65f6\/\u5185\u5b58\/P95<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u5efa\u7acb\u57fa\u7ebf&#xff1a;\u56fa\u5b9a\u8f93\u5165&#043;\u53ef\u590d\u73b0<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>Profiling \u627e\u70ed\u70b9<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u63d0\u51fa\u5047\u8bbe&#xff1a;IO\/CPU\/\u7b97\u6cd5\/\u6570\u636e\u7ed3\u6784<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u5c0f\u6b65\u4f18\u5316&#xff1a;\u4e00\u6b21\u53ea\u6539\u4e00\u4ef6\u4e8b<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u56de\u5f52\u9a8c\u8bc1&#xff1a;\u4e0e\u57fa\u7ebf\u5bf9\u6bd4<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u8bb0\u5f55\u7ed3\u8bba&#xff1a;\u5199\u5165README\/Runbook<\/p>\n<p><\/span><\/p>\n<p>\u8fd9\u5957\u6d41\u7a0b\u80fd\u907f\u514d\u4f60\u5728\u201c\u62cd\u8111\u888b\u4f18\u5316\u201d\u91cc\u6d6a\u8d39\u65f6\u95f4\u3002<\/p>\n<hr \/>\n<h3>2. \u4e09\u7c7b\u74f6\u9888&#xff1a;CPU \/ IO \/ \u5185\u5b58&#xff08;\u5148\u505a\u5206\u7c7b&#xff09;<\/h3>\n<h4>2.1 \u5feb\u901f\u5224\u65ad&#xff1a;\u770b\u73b0\u8c61<\/h4>\n<ul>\n<li>CPU-bound&#xff08;\u7b97\u4e0d\u52a8&#xff09;&#xff1a;CPU \u957f\u671f 100%&#xff0c;\u98ce\u6247\u8d77\u98de&#xff1b;\u52a0\u7ebf\u7a0b\u4e0d\u89c1\u5f97\u5feb<\/li>\n<li>IO-bound&#xff08;\u8bfb\u5199\u6162&#xff09;&#xff1a;CPU \u5f88\u95f2&#xff0c;\u4f46\u4e00\u76f4\u5728\u7b49\u78c1\u76d8\/\u7f51\u7edc&#xff1b;\u52a0\u7f13\u5b58\u53ef\u80fd\u7acb\u7aff\u89c1\u5f71<\/li>\n<li>Memory-bound&#xff08;\u5185\u5b58\/GC&#xff09;&#xff1a;\u5185\u5b58\u98d9\u5347\u3001swap\u3001\u9891\u7e41 GC\u3001\u751a\u81f3 OOM<\/li>\n<\/ul>\n<p>\u4f60\u53ef\u4ee5\u628a\u201c\u603b\u8017\u65f6\u201d\u7c97\u7565\u62c6\u6210&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260122214817-69729b2148607.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u8fd9\u4e0d\u662f\u4e25\u683c\u516c\u5f0f&#xff0c;\u4f46\u8db3\u591f\u6307\u5bfc\u4f60\u5148\u4ece\u54ea\u7c7b\u5de5\u5177\u5165\u624b\u3002<\/p>\n<hr \/>\n<h3>3. \u6700\u5c0f profiling \u5de5\u5177\u94fe&#xff08;\u591f\u7528\u5c31\u884c&#xff09;<\/h3>\n<h4>3.1 \u5148\u7528\u6700\u6734\u7d20\u7684 time<\/h4>\n<p>\u5f88\u591a\u65f6\u5019\u4f60\u53ea\u9700\u8981\u77e5\u9053\u201c\u54ea\u4e00\u6b65\u6700\u6162\u201d\u3002<\/p>\n<p><span class=\"token keyword\">import<\/span> time<\/p>\n<p>t0 <span class=\"token operator\">&#061;<\/span> time<span class=\"token punctuation\">.<\/span>perf_counter<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># step 1<\/span><br \/>\nt1 <span class=\"token operator\">&#061;<\/span> time<span class=\"token punctuation\">.<\/span>perf_counter<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># step 2<\/span><br \/>\nt2 <span class=\"token operator\">&#061;<\/span> time<span class=\"token punctuation\">.<\/span>perf_counter<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;step1:&#034;<\/span><span class=\"token punctuation\">,<\/span> t1 <span class=\"token operator\">&#8211;<\/span> t0<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;step2:&#034;<\/span><span class=\"token punctuation\">,<\/span> t2 <span class=\"token operator\">&#8211;<\/span> t1<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;total:&#034;<\/span><span class=\"token punctuation\">,<\/span> t2 <span class=\"token operator\">&#8211;<\/span> t0<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5de5\u7a0b\u5efa\u8bae&#xff1a;\u628a pipeline \u62c6\u6210 5&#xff5e;10 \u4e2a\u7c97\u7c92\u5ea6\u6b65\u9aa4&#xff0c;\u5148\u505a\u201c\u5b8f\u89c2\u5b9a\u4f4d\u201d\u3002<\/p>\n<hr \/>\n<h4>3.2 cProfile&#xff1a;\u627e\u51fd\u6570\u7ea7\u70ed\u70b9&#xff08;CPU&#xff09;<\/h4>\n<p>\u9002\u7528&#xff1a;\u4f60\u4e0d\u77e5\u9053\u6162\u5728\u54ea\u4e2a\u51fd\u6570\u3002<\/p>\n<p>python -m cProfile -o out.prof your_script.py<\/p>\n<p>\u518d\u7528 pstats \u67e5\u770b Top N&#xff1a;<\/p>\n<p><span class=\"token keyword\">import<\/span> pstats<\/p>\n<p>p <span class=\"token operator\">&#061;<\/span> pstats<span class=\"token punctuation\">.<\/span>Stats<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;out.prof&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\np<span class=\"token punctuation\">.<\/span>sort_stats<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;cumtime&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>print_stats<span class=\"token punctuation\">(<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u4f60\u8981\u5173\u6ce8\u4e24\u4e2a\u6307\u6807&#xff1a;<\/p>\n<ul>\n<li>tottime&#xff1a;\u51fd\u6570\u81ea\u8eab\u8017\u65f6<\/li>\n<li>cumtime&#xff1a;\u5305\u542b\u5b50\u8c03\u7528\u7684\u7d2f\u8ba1\u8017\u65f6<\/li>\n<\/ul>\n<p>\u5f88\u591a\u6570\u636e\u5de5\u7a0b\u74f6\u9888&#xff0c;\u90fd\u4f1a\u5728 cumtime \u91cc\u9732\u5934\u3002<\/p>\n<hr \/>\n<h4>3.3 line_profiler&#xff1a;\u7cbe\u786e\u5230\u884c&#xff08;\u5b9a\u4f4d\u201c\u90a3\u4e00\u884c\u201d&#xff09;<\/h4>\n<p>\u9002\u7528&#xff1a;\u4f60\u5df2\u7ecf\u9501\u5b9a\u51fd\u6570&#xff0c;\u4f46\u60f3\u77e5\u9053\u6162\u5728\u51fd\u6570\u5185\u90e8\u54ea\u91cc\u3002<\/p>\n<p>\u5b89\u88c5&#xff1a;<\/p>\n<p>pip <span class=\"token function\">install<\/span> line_profiler<\/p>\n<p>\u5199\u6cd5&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> line_profiler <span class=\"token keyword\">import<\/span> profile<\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;profile<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">build_features<\/span><span class=\"token punctuation\">(<\/span>df<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    df<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;a&#034;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> df<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;x&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>fillna<span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    df<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;b&#034;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> df<span class=\"token punctuation\">.<\/span>groupby<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;user&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;a&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>transform<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;mean&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> df<\/p>\n<p>\u8fd0\u884c&#xff1a;<\/p>\n<p>kernprof -l -v your_script.py<\/p>\n<p>\u4f60\u4f1a\u5f97\u5230\u9010\u884c\u8017\u65f6&#xff0c;\u8fd9\u5bf9\u5b9a\u4f4d Pandas \u7684\u201c\u9690\u5f62\u6162\u70b9\u201d\u975e\u5e38\u6709\u6548\u3002<\/p>\n<hr \/>\n<h4>3.4 memory_profiler&#xff1a;\u770b\u5185\u5b58\u5cf0\u503c&#xff08;\u7206\u5185\u5b58\u5fc5\u5907&#xff09;<\/h4>\n<p>\u5b89\u88c5&#xff1a;<\/p>\n<p>pip <span class=\"token function\">install<\/span> memory_profiler<\/p>\n<p>\u5199\u6cd5&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> memory_profiler <span class=\"token keyword\">import<\/span> profile<\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;profile<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">load_big<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">import<\/span> pandas <span class=\"token keyword\">as<\/span> pd<br \/>\n    df <span class=\"token operator\">&#061;<\/span> pd<span class=\"token punctuation\">.<\/span>read_parquet<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;big.parquet&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> df<\/p>\n<p>\u8fd0\u884c&#xff1a;<\/p>\n<p>python -m memory_profiler your_script.py<\/p>\n<p>\u4f60\u4f1a\u770b\u5230\u6bcf\u884c\u4ee3\u7801\u5185\u5b58\u53d8\u5316&#xff0c;\u5e38\u7528\u4e8e\u53d1\u73b0\u201c\u590d\u5236\u592a\u591a\u201d\u201c\u4e2d\u95f4\u53d8\u91cf\u592a\u5927\u201d\u3002<\/p>\n<hr \/>\n<h3>4. \u6570\u636e\/AI\u5de5\u7a0b\u6700\u5e38\u89c1\u7684\u6027\u80fd\u5751&#xff08;\u9ad8\u9891\u6e05\u5355&#xff09;<\/h3>\n<p>\u4e0b\u9762\u8fd9\u51e0\u7c7b&#xff0c;\u57fa\u672c\u5360\u4e86 80% \u7684\u6162\u3002<\/p>\n<h4>4.1 Pandas \u7684 apply&#xff1a;\u6700\u7ecf\u5178\u7684\u6027\u80fd\u9677\u9631<\/h4>\n<p>\u5f88\u591a\u4eba\u5199&#xff1a;<\/p>\n<p>df<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;y&#034;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> df<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;text&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span><span class=\"token builtin\">apply<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">lambda<\/span> s<span class=\"token punctuation\">:<\/span> s<span class=\"token punctuation\">.<\/span>lower<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>strip<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u4f1a\u628a\u5411\u91cf\u5316\u8ba1\u7b97\u9000\u5316\u6210 Python \u5faa\u73af\u3002<\/p>\n<p>\u66f4\u597d\u7684\u65b9\u5f0f&#xff08;\u4f18\u5148\u7528\u5411\u91cf\u5316&#xff09;&#xff1a;<\/p>\n<p>df<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;y&#034;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> df<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;text&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">.<\/span>lower<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">.<\/span>strip<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u7ecf\u9a8c\u6cd5\u5219&#xff1a; \u80fd\u7528 str.*\u3001dt.*\u3001numpy \u5c31\u4e0d\u8981 apply\u3002<\/p>\n<hr \/>\n<h4>4.2 groupby &#043; transform \/ merge&#xff1a;\u9690\u6027\u5927\u6740\u5668<\/h4>\n<p>groupby\u3001merge \u5f88\u5f3a&#xff0c;\u4f46\u5f88\u8d35\u3002\u4f60\u8981\u5173\u6ce8&#xff1a;<\/p>\n<ul>\n<li>key \u7684\u57fa\u6570&#xff08;cardinality&#xff09;\u662f\u5426\u8fc7\u5927<\/li>\n<li>\u662f\u5426\u53d1\u751f\u4e86\u610f\u5916\u7684\u7b1b\u5361\u5c14\u79ef<\/li>\n<li>\u662f\u5426\u5728\u5faa\u73af\u91cc\u505a merge<\/li>\n<\/ul>\n<p>\u5efa\u8bae\u5148\u7528 profiling &#043; \u6837\u672c\u6570\u636e\u4f30\u7b97\u590d\u6742\u5ea6\u3002<\/p>\n<hr \/>\n<h4>4.3 Python \u5faa\u73af\u5904\u7406\u5927\u6570\u7ec4&#xff1a;\u7b97\u6cd5\u590d\u6742\u5ea6\u4e0d\u53d8&#xff0c;\u518d\u5feb\u4e5f\u6ca1\u7528<\/h4>\n<p>\u5f53\u4f60\u5bf9 N&#061;1e7 \u7684\u6570\u636e\u505a Python for \u5faa\u73af&#xff1a;<\/p>\n<p><span class=\"token keyword\">for<\/span> x <span class=\"token keyword\">in<\/span> arr<span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><\/p>\n<p>\u4f60\u672c\u8d28\u662f\u5728\u8d4c\u89e3\u91ca\u5668\u901f\u5ea6\u3002 \u5982\u679c\u590d\u6742\u5ea6\u662f (O(N)) \u4e14 N \u5f88\u5927&#xff0c;\u4f60\u8981\u5c3d\u5feb\u8fc1\u79fb\u5230&#xff1a;<\/p>\n<ul>\n<li>numpy \u5411\u91cf\u5316<\/li>\n<li>numba<\/li>\n<li>Cython<\/li>\n<li>\u6216\u4e0b\u6c89\u5230\u6570\u636e\u5e93\/\u5206\u5e03\u5f0f\u8ba1\u7b97\u5f15\u64ce<\/li>\n<\/ul>\n<hr \/>\n<h4>4.4 IO&#xff1a;\u8bfb CSV \u6bd4\u8bfb Parquet \u6162\u5f97\u591a<\/h4>\n<p>\u5f88\u591a pipeline \u6162\u5728\u201c\u683c\u5f0f\u9009\u62e9\u201d&#xff1a;<\/p>\n<ul>\n<li>CSV&#xff1a;\u89e3\u6790\u6210\u672c\u9ad8\u3001\u7c7b\u578b\u63a8\u65ad\u6162<\/li>\n<li>Parquet&#xff1a;\u5217\u5f0f\u5b58\u50a8&#xff0c;\u8bfb\u53d6\u9700\u8981\u7684\u5217\u66f4\u5feb<\/li>\n<li>Feather\/Arrow&#xff1a;\u4e2d\u95f4\u7f13\u5b58\u975e\u5e38\u53cb\u597d<\/li>\n<\/ul>\n<p>\u5de5\u7a0b\u5efa\u8bae&#xff1a;\u8bad\u7ec3\/\u7279\u5f81\u4e2d\u95f4\u5c42\u5c3d\u91cf\u7528 Parquet&#xff0c;\u5e76\u4e14\u663e\u5f0f\u6307\u5b9a dtype&#xff0c;\u51cf\u5c11\u63a8\u65ad\u3002<\/p>\n<hr \/>\n<h3>5. \u4e00\u4e2a\u53ef\u843d\u5730\u7684 profiling \u6846\u67b6&#xff1a;\u628a\u6027\u80fd\u5f53\u6210\u56de\u5f52\u6d4b\u8bd5<\/h3>\n<p>\u4f60\u5199\u5355\u5143\u6d4b\u8bd5\u662f\u4e3a\u4e86\u9632 bug&#xff1b;\u4f60\u5199\u6027\u80fd\u6d4b\u8bd5\u662f\u4e3a\u4e86\u9632\u201c\u6084\u6084\u53d8\u6162\u201d\u3002<\/p>\n<h4>5.1 \u57fa\u7ebf\u4e0e\u5bf9\u6bd4&#xff1a;\u56fa\u5b9a\u8f93\u5165 &#043; \u56fa\u5b9a\u6307\u6807<\/h4>\n<p>\u5efa\u8bae\u7ed9\u6838\u5fc3\u51fd\u6570\u505a\u4e00\u4e2a\u6700\u5c0f\u6027\u80fd\u57fa\u7ebf&#xff1a;<\/p>\n<ul>\n<li>\u8f93\u5165&#xff1a;\u56fa\u5b9a 1 \u4e07\u884c\u6837\u672c&#xff08;\u53ef\u8131\u654f&#xff09;<\/li>\n<li>\u6307\u6807&#xff1a;\u8017\u65f6\u3001\u5185\u5b58\u5cf0\u503c\u3001P95 \u5ef6\u8fdf&#xff08;\u6309\u573a\u666f\u9009&#xff09;<\/li>\n<\/ul>\n<p>  #mermaid-svg-aLuvOG6U7XLls0Qu{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-aLuvOG6U7XLls0Qu .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-aLuvOG6U7XLls0Qu .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-aLuvOG6U7XLls0Qu .error-icon{fill:#552222;}#mermaid-svg-aLuvOG6U7XLls0Qu .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-aLuvOG6U7XLls0Qu .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-aLuvOG6U7XLls0Qu .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-aLuvOG6U7XLls0Qu .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-aLuvOG6U7XLls0Qu .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-aLuvOG6U7XLls0Qu .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-aLuvOG6U7XLls0Qu .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-aLuvOG6U7XLls0Qu .marker{fill:#333333;stroke:#333333;}#mermaid-svg-aLuvOG6U7XLls0Qu .marker.cross{stroke:#333333;}#mermaid-svg-aLuvOG6U7XLls0Qu svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-aLuvOG6U7XLls0Qu p{margin:0;}#mermaid-svg-aLuvOG6U7XLls0Qu .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-aLuvOG6U7XLls0Qu .cluster-label text{fill:#333;}#mermaid-svg-aLuvOG6U7XLls0Qu .cluster-label span{color:#333;}#mermaid-svg-aLuvOG6U7XLls0Qu .cluster-label span p{background-color:transparent;}#mermaid-svg-aLuvOG6U7XLls0Qu .label text,#mermaid-svg-aLuvOG6U7XLls0Qu span{fill:#333;color:#333;}#mermaid-svg-aLuvOG6U7XLls0Qu .node rect,#mermaid-svg-aLuvOG6U7XLls0Qu .node circle,#mermaid-svg-aLuvOG6U7XLls0Qu .node ellipse,#mermaid-svg-aLuvOG6U7XLls0Qu .node polygon,#mermaid-svg-aLuvOG6U7XLls0Qu .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-aLuvOG6U7XLls0Qu .rough-node .label text,#mermaid-svg-aLuvOG6U7XLls0Qu .node .label text,#mermaid-svg-aLuvOG6U7XLls0Qu .image-shape .label,#mermaid-svg-aLuvOG6U7XLls0Qu .icon-shape .label{text-anchor:middle;}#mermaid-svg-aLuvOG6U7XLls0Qu .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-aLuvOG6U7XLls0Qu .rough-node .label,#mermaid-svg-aLuvOG6U7XLls0Qu .node .label,#mermaid-svg-aLuvOG6U7XLls0Qu .image-shape .label,#mermaid-svg-aLuvOG6U7XLls0Qu .icon-shape .label{text-align:center;}#mermaid-svg-aLuvOG6U7XLls0Qu .node.clickable{cursor:pointer;}#mermaid-svg-aLuvOG6U7XLls0Qu .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-aLuvOG6U7XLls0Qu .arrowheadPath{fill:#333333;}#mermaid-svg-aLuvOG6U7XLls0Qu .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-aLuvOG6U7XLls0Qu .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-aLuvOG6U7XLls0Qu .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-aLuvOG6U7XLls0Qu .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-aLuvOG6U7XLls0Qu .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-aLuvOG6U7XLls0Qu .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-aLuvOG6U7XLls0Qu .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-aLuvOG6U7XLls0Qu .cluster text{fill:#333;}#mermaid-svg-aLuvOG6U7XLls0Qu .cluster span{color:#333;}#mermaid-svg-aLuvOG6U7XLls0Qu div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-aLuvOG6U7XLls0Qu .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-aLuvOG6U7XLls0Qu rect.text{fill:none;stroke-width:0;}#mermaid-svg-aLuvOG6U7XLls0Qu .icon-shape,#mermaid-svg-aLuvOG6U7XLls0Qu .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-aLuvOG6U7XLls0Qu .icon-shape p,#mermaid-svg-aLuvOG6U7XLls0Qu .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-aLuvOG6U7XLls0Qu .icon-shape rect,#mermaid-svg-aLuvOG6U7XLls0Qu .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-aLuvOG6U7XLls0Qu .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-aLuvOG6U7XLls0Qu .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-aLuvOG6U7XLls0Qu :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/p>\n<p>\u662f<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/p>\n<p>\u5426<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u56fa\u5b9a\u6837\u672c\u6570\u636e<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u8dd1\u51fd\u6570\/\u6a21\u5757<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u8bb0\u5f55\u8017\u65f6\/\u5185\u5b58<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u4fdd\u5b58\u57fa\u7ebf<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u6bcf\u6b21\u6539\u52a8\u8dd1\u5bf9\u6bd4<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u8d85\u8fc7\u9608\u503c?<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u56de\u6eda\u6216\u4f18\u5316<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u5408\u5e76<\/p>\n<p><\/span><\/p>\n<p>\u8fd9\u4f1a\u8ba9\u4f60\u7684\u9879\u76ee\u4ece\u201c\u529f\u80fd\u80fd\u8dd1\u201d\u5347\u7ea7\u5230\u201c\u6027\u80fd\u53ef\u63a7\u201d\u3002<\/p>\n<hr \/>\n<h3>6. \u4f18\u5316\u7b56\u7565\u7684\u4f18\u5148\u7ea7&#xff1a;\u5148\u505a\u201c\u6536\u76ca\u6700\u5927\u201d\u7684<\/h3>\n<p>\u4e0b\u9762\u662f\u6211\u5728\u6570\u636e\/AI\u5de5\u7a0b\u91cc\u5e38\u7528\u7684\u4f18\u5316\u987a\u5e8f&#xff1a;<\/p>\n<li>\u5220\u6389\u4e0d\u5fc5\u8981\u7684\u5de5\u4f5c&#xff08;\u51cf\u5c11\u8bfb\u53d6\u5217\u3001\u51cf\u5c11\u4e2d\u95f4\u8868\u3001\u51cf\u5c11\u91cd\u590d\u8ba1\u7b97&#xff09;<\/li>\n<li>\u6539\u53d8\u6570\u636e\u683c\u5f0f\u4e0e IO&#xff08;Parquet\u3001\u7f13\u5b58\u3001\u6279\u5904\u7406&#xff09;<\/li>\n<li>\u7528\u5411\u91cf\u5316\u66ff\u4ee3 Python \u5faa\u73af&#xff08;Pandas\/Numpy&#xff09;<\/li>\n<li>\u964d\u4f4e\u7b97\u6cd5\u590d\u6742\u5ea6&#xff08;\u4ece (O(N^2)) \u5230 (O(N \\\\log N))&#xff09;<\/li>\n<li>\u5e76\u884c\/\u5206\u5e03\u5f0f&#xff08;\u6700\u540e\u518d\u4e0a&#xff0c;\u591a\u7ebf\u7a0b\/\u591a\u8fdb\u7a0b\/Ray\/Spark&#xff09;<\/li>\n<p>\u4e3a\u4ec0\u4e48\u5e76\u884c\u653e\u6700\u540e&#xff1f; \u56e0\u4e3a\u4f60\u6ca1\u5b9a\u4f4d\u70ed\u70b9&#xff0c;\u76f2\u76ee\u5e76\u884c\u53ea\u4f1a\u628a\u590d\u6742\u5ea6\u653e\u5927&#xff0c;\u5e76\u5f15\u5165\u66f4\u591a\u4e0d\u53ef\u63a7\u56e0\u7d20\u3002<\/p>\n<hr \/>\n<h3>7. \u5c0f\u7ed3&#xff1a;\u6027\u80fd\u610f\u8bc6&#061;\u53ef\u89e3\u91ca\u3001\u53ef\u590d\u73b0\u3001\u53ef\u6301\u7eed<\/h3>\n<p>\u4f60\u4e0d\u9700\u8981\u4e00\u5f00\u59cb\u5c31\u5199\u51fa\u201c\u6781\u81f4\u5feb\u201d\u7684\u4ee3\u7801\u3002 \u4f60\u9700\u8981\u7684\u662f\u4e00\u5957\u65b9\u6cd5&#xff0c;\u8ba9\u4f60\u9047\u5230\u6027\u80fd\u95ee\u9898\u65f6&#xff1a;<\/p>\n<ul>\n<li>\u4e0d\u731c<\/li>\n<li>\u4e0d\u62cd\u8111\u888b<\/li>\n<li>\u4e0d\u9760\u8fd0\u6c14<\/li>\n<\/ul>\n<p>\u800c\u662f\u7528 profiling \u8bb2\u6e05\u695a&#xff1a;<\/p>\n<p>\u201c\u6162\u5728\u8fd9\u91cc&#xff0c;\u56e0\u4e3a\u8fd9\u4e2a\u51fd\u6570\u5360\u4e86 60% cumtime&#xff1b; \u6211\u628a\u5b83\u4ece apply \u6539\u6210\u5411\u91cf\u5316\u540e&#xff0c;\u8017\u65f6\u4ece 12s \u964d\u5230 2.8s&#xff1b; \u56de\u5f52\u6570\u636e\u96c6\u4e0b\u6307\u6807\u4e0d\u53d8&#xff0c;\u6027\u80fd\u57fa\u7ebf\u66f4\u65b0\u4e3a 3s\u3002\u201d<\/p>\n<p>\u8fd9\u5c31\u662f\u6570\u636e\/AI\u5de5\u7a0b\u91cc\u771f\u6b63\u7684\u201c\u53ef\u7ef4\u62a4\u201d\u3002<\/p>\n<hr \/>\n<h3>\u4f60\u53ef\u4ee5\u76f4\u63a5\u62ff\u6765\u7528\u7684\u884c\u52a8\u6e05\u5355<\/h3>\n<p>\u5982\u679c\u4f60\u4eca\u5929\u5c31\u8981\u5f00\u59cb\u505a profiling&#xff0c;\u6309\u8fd9\u4e2a\u987a\u5e8f&#xff1a;<\/p>\n<li>\u628a pipeline \u5207\u6210 5&#xff5e;10 \u6b65&#xff0c;\u5148 time \u7c97\u5b9a\u4f4d<\/li>\n<li>\u7528 cProfile \u627e Top 20 \u70ed\u70b9\u51fd\u6570<\/li>\n<li>\u5bf9 Top 1&#xff5e;3 \u51fd\u6570\u4e0a line_profiler<\/li>\n<li>\u5982\u679c\u6709 OOM\/\u5361\u987f&#xff0c;\u4e0a memory_profiler<\/li>\n<li>\u56fa\u5b9a\u6837\u672c\u6570\u636e&#xff0c;\u5efa\u7acb\u6027\u80fd\u57fa\u7ebf&#xff08;\u5199\u5230 README&#xff09;<\/li>\n<h3>\u4e0b\u4e00\u7ae0&#xff1a;<\/h3>\n<p>\u300a\u7b2c14\u7ae0 \u4ee3\u7801\u8d28\u91cf\u6e05\u5355&#xff1a;\u4ece\u201c\u80fd\u8dd1\u201d\u5230\u201c\u53ef\u4ea4\u4ed8\u201d\u300b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8&#xff1a;\u4f60\u4ee3\u7801\u6162\u5728\u54ea&#xff1f;profiling \u7684\u5de5\u7a0b\u5316\u601d\u8def0. \u672c\u7ae0\u76ee\u6807\u4e0e\u9002\u7528\u573a\u666f1. \u6027\u80fd\u4f18\u5316\u7684\u5e95\u5c42\u903b\u8f91&#xff1a;\u5148\u5ea6\u91cf&#xff0c;\u518d\u4f18\u53162. \u4e09\u7c7b\u74f6\u9888&#xff1a;CPU \/ IO \/ \u5185\u5b58&#xff08;\u5148\u505a\u5206\u7c7b&#xff09;2.1 \u5feb\u901f\u5224\u65ad&#xff1a;\u770b\u73b0\u8c613. \u6700\u5c0f profiling \u5de5\u5177\u94fe&#xff08;\u591f\u7528\u5c31\u884c&#xff09;3.1 \u5148\u7528\u6700\u6734\u7d20\u7684 time3.2 cProfile&#xff1a;\u627e\u51fd\u6570\u7ea7<\/p>\n","protected":false},"author":2,"featured_media":64255,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,62],"topic":[],"class_list":["post-64257","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-python","tag-62"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8\uff1a\u4f60\u4ee3\u7801\u6162\u5728\u54ea\uff1fprofiling \u7684\u5de5\u7a0b\u5316\u601d\u8def - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/64257.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8\uff1a\u4f60\u4ee3\u7801\u6162\u5728\u54ea\uff1fprofiling \u7684\u5de5\u7a0b\u5316\u601d\u8def - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8&#xff1a;\u4f60\u4ee3\u7801\u6162\u5728\u54ea&#xff1f;profiling \u7684\u5de5\u7a0b\u5316\u601d\u8def0. \u672c\u7ae0\u76ee\u6807\u4e0e\u9002\u7528\u573a\u666f1. \u6027\u80fd\u4f18\u5316\u7684\u5e95\u5c42\u903b\u8f91&#xff1a;\u5148\u5ea6\u91cf&#xff0c;\u518d\u4f18\u53162. \u4e09\u7c7b\u74f6\u9888&#xff1a;CPU \/ IO \/ \u5185\u5b58&#xff08;\u5148\u505a\u5206\u7c7b&#xff09;2.1 \u5feb\u901f\u5224\u65ad&#xff1a;\u770b\u73b0\u8c613. \u6700\u5c0f profiling \u5de5\u5177\u94fe&#xff08;\u591f\u7528\u5c31\u884c&#xff09;3.1 \u5148\u7528\u6700\u6734\u7d20\u7684 time3.2 cProfile&#xff1a;\u627e\u51fd\u6570\u7ea7\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/64257.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-22T21:48:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260122214816-69729b204915b.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64257.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/64257.html\",\"name\":\"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8\uff1a\u4f60\u4ee3\u7801\u6162\u5728\u54ea\uff1fprofiling \u7684\u5de5\u7a0b\u5316\u601d\u8def - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-22T21:48:18+00:00\",\"dateModified\":\"2026-01-22T21:48:18+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/64257.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/64257.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64257.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8\uff1a\u4f60\u4ee3\u7801\u6162\u5728\u54ea\uff1fprofiling \u7684\u5de5\u7a0b\u5316\u601d\u8def\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8\uff1a\u4f60\u4ee3\u7801\u6162\u5728\u54ea\uff1fprofiling \u7684\u5de5\u7a0b\u5316\u601d\u8def - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/64257.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8\uff1a\u4f60\u4ee3\u7801\u6162\u5728\u54ea\uff1fprofiling \u7684\u5de5\u7a0b\u5316\u601d\u8def - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8&#xff1a;\u4f60\u4ee3\u7801\u6162\u5728\u54ea&#xff1f;profiling \u7684\u5de5\u7a0b\u5316\u601d\u8def0. \u672c\u7ae0\u76ee\u6807\u4e0e\u9002\u7528\u573a\u666f1. \u6027\u80fd\u4f18\u5316\u7684\u5e95\u5c42\u903b\u8f91&#xff1a;\u5148\u5ea6\u91cf&#xff0c;\u518d\u4f18\u53162. \u4e09\u7c7b\u74f6\u9888&#xff1a;CPU \/ IO \/ \u5185\u5b58&#xff08;\u5148\u505a\u5206\u7c7b&#xff09;2.1 \u5feb\u901f\u5224\u65ad&#xff1a;\u770b\u73b0\u8c613. \u6700\u5c0f profiling \u5de5\u5177\u94fe&#xff08;\u591f\u7528\u5c31\u884c&#xff09;3.1 \u5148\u7528\u6700\u6734\u7d20\u7684 time3.2 cProfile&#xff1a;\u627e\u51fd\u6570\u7ea7","og_url":"https:\/\/www.wsisp.com\/helps\/64257.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-22T21:48:18+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260122214816-69729b204915b.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/64257.html","url":"https:\/\/www.wsisp.com\/helps\/64257.html","name":"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8\uff1a\u4f60\u4ee3\u7801\u6162\u5728\u54ea\uff1fprofiling \u7684\u5de5\u7a0b\u5316\u601d\u8def - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-22T21:48:18+00:00","dateModified":"2026-01-22T21:48:18+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/64257.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/64257.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/64257.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7b2c\u5341\u4e09\u7ae0 \u6027\u80fd\u610f\u8bc6\u5165\u95e8\uff1a\u4f60\u4ee3\u7801\u6162\u5728\u54ea\uff1fprofiling \u7684\u5de5\u7a0b\u5316\u601d\u8def"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=64257"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64257\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/64255"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=64257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=64257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=64257"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=64257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}