Paste any function and get back specific optimizations for performance, memory usage, and time complexity with before-and-after examples.
By Arshad Hossain
How to Use
Copy the prompt below into your preferred LLM, then paste your code snippet where indicated.
The Prompt
Go through the following function and suggest optimizations to improve its performance, memory usage, and time complexity. For each suggestion, explain why it improves performance and show the optimized version.
Provide your analysis in this format:
1. Current complexity analysis (time and space)
2. Identified bottlenecks
3. Optimization suggestions with explanations
4. Optimized code with comments
5. New complexity analysis after optimization
Here is the code:
[paste your code here]
Why "Code Performance Optimizer" Works
This prompt produces reliable output because it leverages reasoning elicitation and sequential task breakdown and output formatting. Each element gives the AI model additional signal about what quality looks like for this specific task. Expect production-quality code that handles edge cases and follows your stack conventions. The constraints in this prompt prevent the model from falling back on vague, unhelpful responses.
Pro Tips for Using "Code Performance Optimizer"
These coding tips will help you get stronger results when using "Code Performance Optimizer" and similar prompts in this category.
Always specify the programming language, framework version, and runtime environment - "write a function" without context produces unusable code.
Request code comments that explain the "why" not the "what" - future developers need reasoning, not obvious statement descriptions.
Ask for unit tests alongside the implementation. Writing tests after the fact is harder than generating them together.
When to Use "Code Performance Optimizer"
"Code Performance Optimizer" is particularly useful in these situations. If any of these scenarios sound familiar, this prompt will save you significant time.
You are building a feature from scratch and need clean, well-structured code that follows best practices for your stack.
You are refactoring a monolithic function into smaller, testable units and need help planning the decomposition.
You are integrating a third-party API and need boilerplate code with proper error handling and retry logic.
What You Will Get from "Code Performance Optimizer"
When you use "Code Performance Optimizer" with ChatGPT, Claude, or Gemini, here is what to expect in the AI output.
Clean, commented code following language-specific conventions with error handling for edge cases.
Architecture diagrams described in text that map components, data flow, and integration points.
Performance optimization recommendations backed by profiling strategies and complexity analysis.
How to Customize "Code Performance Optimizer"
Adapt "Code Performance Optimizer" to your specific situation by modifying these key areas. The more context you add, the better the results.
Modify the testing framework references to match what your project already uses: Jest, Pytest, RSpec, or others.
Replace the language placeholder with your exact tech stack including framework version and runtime environment.
Adjust the complexity level based on whether this is a prototype, MVP, or production-grade implementation.