That's over the course of a 2 hour race, when the difference in speed between the fastest and slowest car is about 1-2 seconds per lap on a 3 minute lap.
Nobody passes another car like they're standing still. But, often a better car can brake just a bit harder and get better position on a corner. Or it can go just a bit faster on the straight and be half a car-length ahead at the end of the straight.
The way these things are depicted in movies is more like the races you sometimes see where it's a pro racing driver vs 100 amateurs.