If you are able, do it before you start residency. For IMG, if you do step 3 and your score is released before match day, then you can qualify for H1b visa which is great for your future as you will be able to easily stay in the US and convert it to green card without the need to do a J1 waiver.
The other reason why you should do it before residency is because you will be very busy working as an intern and you will probably lose all information from the other specialties. Its best when you are just fresh from finishing step 2Ck