some servers / cpus / os's remember the patterns. like cache.
Since you doing the same thing 4 times, I'm sure there are ways it can cut corners, What I am guessing is that the first way you do it, it thinks of it as one long process (example1) but in the second way is sees the reused code and runs it like cache (example2) or it could be the first process is to big to fit it all in the (ram example3).
example1: 0111110000110111110000111011111000011110111110000
example2: 0111110000|11|0111110000|111|0111110000|1111|0111110000
example3: 0111110000011111000001111100000111110000 example3: loop: 0111110000
I know ubuntu server does this with repeated mysql queries. I can save them in cache, although really the only difference in time is 10-40mms but it adds up. When I was in school there was classes that showed you have to make programs (perl / php) use that cache to be faster.
But, it might depend on the program, what language is it, what is it compiled in or how it was programmed.