A prompt for speeding up slow code
Copy this into ChatGPT, Claude, Gemini or any other AI. It is the professional version of a request most people type in a few words.
1What most people type
“why is my python script slow”
2The professional prompt
My Python script is running slower than I expected, and I would like help finding out why and how to speed it up. Here is the script: [paste your code here]. It takes about [how long it runs] to run on [size or type of input data], and I expected it to take about [expected time, if you have one]. I am running Python [version] on [your operating system].
Please read the code and point out the most likely causes of the slowness, ordered from biggest likely impact to smallest. For each one, explain in plain language why it is slow and show a corrected version of the relevant lines. Pay attention to things like inefficient loops, repeated work, poor choice of data structures, unnecessary file or network access, and heavy use of libraries that could be replaced by faster approaches.
Also tell me how to measure where the time is actually going, for example with a profiler or simple timing, so I can check your suggestions rather than trust them blindly. If you cannot tell what is slow without more information, ask me up to three specific questions before guessing, and say clearly which suggestions are certain and which are only educated guesses. Keep the answer practical and avoid rewriting the whole script unless that is truly the best fix.
Before you use it, replace each [highlighted part] with your own details.
Why this version works
- Placeholders for your code and run time give the AI the facts it needs to diagnose properly.
- Asking for causes ranked by impact helps you fix the biggest problem first.
- Asking how to measure lets you confirm the cause instead of guessing.
- Letting the AI ask questions and flag guesses stops it from inventing a confident but wrong answer.
Make it even better
- Paste the actual slow code, including any functions it calls, so the assistant can see where time might be going.
- Say how slow it is now and how fast you need it, such as "takes 30 seconds, needs under 5."
- Describe your setup, including the language version, the size of your data, and any tools or limits you must stick with.
Free · no sign-up
Need something different?
Say what you want in your own words and the Prompt Translator writes the professional prompt for you.
More prompts for coding
This prompt was written by an AI through our Prompt Translator, exactly as a visitor would get it. Read it and adjust it before you use it. See the whole prompt library.