5 ms·
The C++ version is taking a compile and runtime short cut by using printf instead of iostream. This pull request has timings with this changed: https://github.
by muizelaar 8y ago
The C++ version is taking a compile and runtime short cut by using printf instead of iostream.
This pull request has timings with this changed: https://github.com/atilaneves/pythagoras/pull/1#issuecomment-450661579 https://github.com/atilaneves/pythagoras/pull/1#issuecomment...
- clappski 8y agoUsing the <iostream> stuff isn’t really idiomatic - on both modern and legacy code bases I’ve used operator<< overloads on custom types, but never called std::cout in a hot loop or used std::endl to do anything but actually flush the stream.
- muizelaar 8y agoWhat would you suggest is C++ recommended way for doing io?
- IshKebab 8y agoI would use std::cout but output "\n" instead of endl.
- prewett 8y agoIs std::endl guaranteed to flush the stream? I’d think you’d be better off with std::cout::flush(), std::flush if you prefer manipulators. It would certainly be clearer, assuming it’s not temporary debug code.
- wbkang 8y agoIt is guaranteed to flush.
- TheCoelacanth 8y agoIt is. That is the only reason to use it other than '\n'
- pjmlp 8y agoSure it is. Not everyone is micro-optimizing their code just to save a couple of needless extra ms. I never, ever since 1993, had to work on a C++ project where stdio vs iostream performance made any worthwhile difference, besides stdio being less secure to use.
- fnord123 8y agoYeah you also need to be careful mixing C++ and C iostream/stdio as there is synchronization if you mix them. And if you don't then you should use ` std::ios_base::sync_with_stdio(false);` to prevent performance issues.
- atilaneves 8y agoIt's valid C++ and requires no external dependencies.