6 ms·
printf code should not appear in timed scope.
by petermcneeley 8y ago
printf code should not appear in timed scope.
- tom_ 8y agoWhy not? It clearly doesn't add anything meaningful to the run time, and helps avoid the question of whether the loop got optimised out.
- petermcneeley 8y agoI timed his code on Windows and it certainly adds to the runtime. To prevent the loop from being optimized out I created a pre-sized vector to index the ith ouput and print it outside the timed scope. I have worked in the game industry and have many bad experiences with printf/logging consuming so much performance it makes games unplayable.
- e12e 8y agoFor a simple example, surely the easiest/safest way to make sure the loop remains a loop, is to look at the assembler output?
- cjhanks 8y ago`printf` implements a barrier which cannot be crossed by an optimizer.
- twtw 8y agoMeh. Aras is comparing apples to apples, so I don't see how it matters.
- petermcneeley 8y agoI agree its a general nitpick but it actual furthers Aras point if he removed the printf and the difference in performance (c-style vs ranges) was to increase.