Depending on how complex the code is, you don't need that big prompt with ChatGPT.
I have sped up a project by simply saying "What are all the possible ways I can speed up this code?" Then it'll list everything it finds, then ask it to rewrite the code.
Edit: Also, I find I didn't need to do this (because a speed up implies semantic similarity), but you can also add "change it without altering the semantics of the code" and in this way it'll be the same and should pass tests