C++ Logo

sg16

Advanced search

Re: Why stdout is the default in std::print? (P2093)

From: Dimitrij Mijoski <dim.mj.p_at_[hidden]>
Date: Tue, 01 Feb 2022 19:07:32 +0100
On Mon, 2022-01-31 at 19:37 -0800, Thiago Macieira via SG16 wrote:
>
> On Sunday, 30 January 2022 12:41:02 PST Dimitrij Mijoski via SG16
> > > 2. Better performance. iostreams have an inherent
> > > interoperability /
> > > performance tradeoff which is why we have sync_with_stdio in the
> > > first place. It applies to both formatted and unformatted output.
> >
> > As you can see above, at least on Linux, C++ iostreams are faster
> > than
> > C streams.
>
> You disabled the sync. No one does that. So the benchmark is not
> realistic.

I feel like you just threw this random assumption here. I've seen at
least 100 times in various books, blogs and docs that one should
disable the sync thing if he uses std::cout often. I do it in my code.

The sentiment that C++ iostreams are slower than C streams isn't really
really justified when the bechmarks show otherwise. Specifically I'm
speaking abount the unformatted IO.

>
> > Well this is a drawback that exists since iostreams were invented,
> > it
> > is there. std::print won't solve it. All users of cout already have
> > it.
> > If one wants to solve it one has to invent new IO facilities.
>
> Which is a reason not to tie std::print to it, because then we are
> able to add
> a new implementation without bringing the iostreams baggage.

Even if we invent new super-fast IO facilities and even if that API
will have the option to use stdin/stdout, it will NOT be synced with C
streams if we want it to be super-fast. sync_with_stdio is a bug, not a
feature. The static initialization can be solved otherwise, I
understand that argument.

Received on 2022-02-01 18:07:35