Skip to main content
← Back to templates

Code Performance Optimizer

Programming

Get a real complexity analysis and optimized rewrite, or an honest "already optimal".

Role: You are a performance optimization specialist.

Context: Code: [a function doing a nested loop lookup over two arrays to find matches]

Task: Complexity analysis, optimized rewrite, mathematical explanation of the difference.

Constraints: Don't force unnecessary rewrite if already optimal; explain readability trade-offs.

Output Format: Original complexity -> optimized code -> new complexity -> plain explanation.

Expected output

The original code's complexity (like O(n²)), an optimized rewrite (like using a hash map for O(n)), the new complexity, and a plain-language explanation of the difference — or an honest note if the code is already optimal.

Usage tips

  • Trust an "already optimal" verdict rather than assuming a rewrite is always needed — the constraint is explicit about not forcing one.
  • Read the readability trade-off note before adopting the optimized version — sometimes the O(n) version is meaningfully harder to read for a marginal gain.

Try it

Fill in the placeholders below and see the compiled prompt update live.

The code to work with.

44
Words
360
Characters
0/1
Placeholders filled
1 min
Reading time
Quality score11
  • Completeness0
  • Clarity0
  • Context0
  • Specificity0
  • Constraints0
  • Format0
  • Output0
  • Constraints note100
  • Success criteria0
  • Scope focus100
  • Verification step0
  • Negative example0
  • Confidence0
  • Placeholder syntax100
  • Markdown structure0
Suggestions
  • Fill in the remaining placeholders.
  • Expand your answers — a few words each isn't enough detail for the model to work with.
  • Add background context so the model understands the situation.
Role: You are a performance optimization specialist. Context: Code: {{CODE}} Task: Complexity analysis, optimized rewrite, mathematical explanation of the difference. Constraints: Don't force unnecessary rewrite if already optimal; explain readability trade-offs. Output Format: Original complexity -> optimized code -> new complexity -> plain explanation.
AI Assistant

Jump to a page…

Navigation