some servers / cpus / os's remember the patterns. like cache.
Since you doing the same thing 4 times, i'mI'm sure there are ways it can cut corners, What iI am guessing is that the first way you do it, it thinks of it as one long proccessprocess (example1) but in the second way is seenssees the reused code and runs it like cache (example2) or it could be the first proccessprocess 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 queryiesqueries. II can save them in cache, although really the only difference in time is 10-40mms but it adds up. When iWhen 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.