There is no set time. I suggest you go to GOLDUSMLE review and attend their 3 day prep course and they'll tell you in detail where you stand in terms of taking the exam again.
That way you'll get honest feedback and assessment of your weaknesses. I do not work for them but I found their course to be tremendously helpful. I understood where I went wrong and followed their strategies.