conduit icon indicating copy to clipboard operation
conduit copied to clipboard

`std::endl` is expensive

Open eschnett opened this issue 10 months ago • 4 comments

Using std::endl to terminate a line is expensive. See e.g. https://en.cppreference.com/w/cpp/io/manip/endl. std::endl flushes the stream, and this can be quite expensive, especially when the output is redirected to a file on a shared file system.

eschnett avatar Feb 24 '25 17:02 eschnett

Is there a particular place where we're using std::endl to terminate a line that you have in mind? Or are you opening this ticket so that we look at all instances across Conduit?

JustinPrivitera avatar Feb 25 '25 06:02 JustinPrivitera

I looked at the code, and it seems that conduit is using std::endl instead of \n everywhere. I don't think that's a good programming guideline. It might be worthwhile changing all std::endl to \n, and adding explicit calls to std::flush where necessary (if necessary at all).

eschnett avatar Feb 25 '25 14:02 eschnett

We can investigate this for a future release.

JustinPrivitera avatar Feb 26 '25 05:02 JustinPrivitera

Yes, the flush included in std::endl has a price. We can revisit -- we also have fmt that can help

cyrush avatar Feb 26 '25 14:02 cyrush