Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

printf code should not appear in timed scope.


Why not? It clearly doesn't add anything meaningful to the run time, and helps avoid the question of whether the loop got optimised out.


I 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.


`printf` implements a barrier which cannot be crossed by an optimizer.


For a simple example, surely the easiest/safest way to make sure the loop remains a loop, is to look at the assembler output?


Meh. Aras is comparing apples to apples, so I don't see how it matters.


I 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: