跳到主要内容
知仓学习社ZHICANG

python-performance

Profiles Python code for performance bottlenecks and memory issues. Use when Python code is slow or when profiling for optimization before a release.

不碰外部(只输出文字)无严重或高危命中athola/claude-night-market

它会碰到什么

扫了多少6 个文本文件,12 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Python Performance Optimization

Profiling and optimization patterns for Python code.

Table of Contents

  1. [Quick Start](#quick-start)

Quick Start

# Basic timing
import timeit

time = timeit.timeit("sum(range(1000000))", number=100)
print(f"Average: {time / 100:.6f}s")

Verification: Run the command with --help flag to verify availability.

When To Use

  • Identifying performance bottlenecks
  • Reducing application latency
  • Optimizing CPU-intensive operations
  • Reducing memory consumption
  • Profiling production applications
  • Improving database query performance

When NOT To Use

  • Async concurrency - use python-async

instead

  • CPU/GPU system monitoring - use conservation:cpu-gpu-performance
  • Async concurrency - use python-async

instead

  • CPU/GPU system monitoring - use conservation:cpu-gpu-performance

Modules

This skill is organized into focused modules for progressive loading:

[profiling-tools](modules/profiling-tools.md)

CPU profiling with cProfile, line profiling, memory profiling, and production profiling with py-spy. Essential for identifying where your code spends time and memory.

[optimization-patterns](modules/optimization-patterns.md)

Eleven proven optimization patterns including list comprehensions, generators, caching, string concatenation, data structures, NumPy, multiprocessing, database operations, and loop transformations (what works in Python vs the compiler).

[memory-management](modules/memory-management.md)

Memory optimization techniques including leak tracking with tracemalloc and weak references for caches. Depends on profiling-tools.

[benchmarking-tools](modules/benchmarking-tools.md)

Benchmarking tools including custom decorators and pytest-benchmark for verifying performance improvements.

[best-practices](modules/best-practices.md)

Best practices, common pitfalls, and exit criteria for performance optimization work. Synthesizes guidance from profiling-tools and optimization-patterns.

Exit Criteria

  • Profiled code to identify bottlenecks
  • Applied appropriate optimization patterns
  • Verified improvements with benchmarks
  • Memory usage acceptable
  • No performance regressions

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。