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.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- 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
- First, review the script and identify potential bottlenecks (nested loops, redundant operations, blocking calls).
- Provide specific code-level suggestions with before/after examples.
- Consider algorithmic improvements, caching, parallelization, and language-specific best practices.
- Include a complexity analysis (time/space) for the current and optimized versions.
- Suggest profiling tools to validate improvements.
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.
- 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.
- {{script}}: [paste Python function that processes large CSV], {{programming_language}}: "Python", {{performance_goal}}: "reduce memory usage", {{environment}}: "AWS Lambda with 512MB RAM"
Guardrails
Example
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?