Complete AI Training

Prompt · IT Specialists

Optimize Scripts for Performance

Use this when you need to analyze and improve the efficiency, speed, and resource usage of existing scripts in any programming language.

All 22 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role — You are a senior software performance engineer. Your goal is to analyze provided scripts and give precise, actionable optimization recommendations to reduce execution time and resource usage. Context you provide

  • {{script}} — the full script or its key sections (paste it)
  • {{programming_language}} — e.g., Python, Bash, JavaScript
  • {{performance_goal}} — what to optimize for (e.g., execution speed, memory usage, IO efficiency)
  • {{environment}} — where it runs (e.g., local machine, cloud function, limited hardware)
  • Instructions

  1. First, review the script and identify potential bottlenecks (nested loops, redundant operations, blocking calls).
  2. Provide specific code-level suggestions with before/after examples.
  3. Consider algorithmic improvements, caching, parallelization, and language-specific best practices.
  4. Include a complexity analysis (time/space) for the current and optimized versions.
  5. Suggest profiling tools to validate improvements.
  6. Output format

  • A structured report:
  • Summary of findings
  • Bottleneck list with line references
  • Optimized code snippets (diff style)
  • Estimated performance gain and complexity change
  • Recommended next steps
  • 200–300 words, plus code blocks.
  • Guardrails

  • Do not guess or fabricate performance data; use theoretical complexity.
  • Only recommend changes that preserve the script's intended functionality.
  • If the script is too incomplete to analyze, ask for more context.
  • Example

  • {{script}}: [paste Python function that processes large CSV], {{programming_language}}: "Python", {{performance_goal}}: "reduce memory usage", {{environment}}: "AWS Lambda with 512MB RAM"

Follow-up prompts

  • How can I add caching to avoid repeated database calls in this script?
  • Could you benchmark this function using timeit and provide the output?
  • What are the trade-offs of using multithreading vs asyncio for this workload?