-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace std::endl with the newline char #178
Conversation
This prevents std::flush that std::endl contains
I‘m not sure about the context for the PR, but have some questions:
|
First of all it is known that std::endl can lead to extreme slowdowns especially when used with file io. Example:
Took 57.09 seconds while
took only 1.48 s. Is it necessary? For fileio yes, for normal cout it depends on the implementation afaik. Yes a missing flush may in some implementation lead to seeing the output a bit later The policy to avoid std::endl is in use in many other open and closed source C++ projects. The flush should never be wanted but if it somehow is than this would be an outlier. There are better alternatives like using cerr which never buffers anyway or manually flushing with std::flush which is more verbose and better conveys the intent. It is very unfortunate that std::endl is in almost all hello world programs for C++ out there. It really was a bad decision to include the std::flush. |
One note: at least for |
That sounds like a sound plan to me. It would ensures that the LOG call is visible on all implementations and we would not flush on every line break in a call to the logging function. And with a '\n' everywhere policy it would be easier to spot if we erroneously flush in file io, which is almost always a mistake. |
Personally, I find Performance-wise, it only really matters when we are outputting millions of lines (see the example above) and this is almost never the case unless we're doing some kind of explicit export ( We should have '\n' where it's needed (mostly that should be file I/O) but I would prefer not enforcing it for "normal" outputs to Regarding this PR: I don't object to merging but I'm also not particularly fond of it. Again, I find |
First, thanks Daniel, for spotting this. In particular better performance on file-io is helpful. I think it is also for the smaller models this may very well shave of quite some percents of the performance and I know plenty of people misusing outputs :-). Regarding readabilty, cant we just do Tim, why is flushing on the console / on std::cout not critical? |
@sjunges as I've said, this only has an effect when there are millions of lines of output. If this is what we send to Also, for file output, flushing is usually more costly (I guess because one has to access secondary storage). If you change the example of @dbasgoeze from a file stream to The problem I see with For me, the best solution would be to replace only the "critical" file I/O std::endl. However, I can see that those are not easy to find right now and when code readability is the only concern, it's probably not worth the effort. I'd suggest this compromise:
|
I've dug into the STORM_LOG_* implementation based on the L3PP_LOG_* macros. So a std::flush in a STORM_LOG_ERROR will not be passed to the output stream but will instead lead to a flush on the stringstream. |
Thank you very much for looking into this @dbasgoeze I'm fine with merging now. Any objections? |
not from my side, thanks everyone |
This prevents std::flush that std::endl contains, which is in all cases I've checked unnecessary can lead to extreme slowdowns.
Especially there where many chains of std::endl which are dramatically slow on some systems.
This PR was not made with just a regex which is important as it does not remove the std::endl in the FileTest and hopefully does not break the JIT implementation as there was an escaped std::endl which was also replaced with an escaped '\n'.