If you've ever started a race (or any run for that matter) and shortly into it felt like it's a struggle, then the chances are that you've just overshot things a little and your body is playing catchup. To avoid this feeling, a warm up that eases you into your run will go a long way. This means though that the more intense your planned run/race, the more you need to warm up.
For a regular run, I would always recommend starting with a slow jog to gently elevate your heart rate. Around 5 minutes is sufficient. You can then perform a few leg swings back and forth and from side to side, as well as some lunges, and provided that it's just an easy run then this should be enough to then get going.
If you're doing a workout, then you can follow the above but once the dynamic movements are done, perform 3-4 strides where you accelerate up to around 90% effort (around 3k/mile pace) for 10-15 seconds, hitting your top speed for around 2 seconds before backing off. This will prime your body for the workout to follow.
Racing requires a more vigorous warm up. It may seem counterproductive to expend energy prior to a race, but you should consider it more that you are tapping into and releasing energy that you'll later be able to deploy in good measure. I really like the warmup prescribed by Tom 'Tinman' Schwartz. It's best done so that you finish it with 20-30 minutes to spare before your race starts. That way you get the benefit of the activation without any lingering fatigue. It goes as follows:
Warm up jog (5-10 minutes)
Run at tempo effort, somewhere between your half marathon and marathon pace (5 minutes)
Recovery jog (1 minute)
Race pace 100m strides (5 x 30 seconds with 50m recovery jog)
Sprints (5 x 10 seconds with 20 seconds recovery jog)
Try this out before your next race, you may not feel amazing during the warm up but it will blast the cobwebs away so that you hopefully don't feel them at the start of the race.