I'm feeling extremely thick right now, but what does this logic really do? I mean the whole duration dance.

I read this as if we have executed for more than 500 millis, then print the results, and start a new measurement, and if we have executed for less than 500 millis, then "continnue" the measurement for another batch. Is that what it's supposed to do?