[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 4bc0910 5/6: Test std::ostream(nullptr) as we
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 4bc0910 5/6: Test std::ostream(nullptr) as well |
Date: |
Thu, 5 Aug 2021 17:10:00 -0400 (EDT) |
branch: master
commit 4bc09103ab6fb75351e5ba846a4ad675a8428339
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Test std::ostream(nullptr) as well
The behavior is indeed well defined--see:
https://stackoverflow.com/a/25690637
This technique costs about a millisecond more than using a custom
streambuf that overloads overflow(). Constructing it locally costs
about another millisecond, and avoids the problem that replacing
the streambuf in a global instance has a global effect.
---
null_stream_test.cpp | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/null_stream_test.cpp b/null_stream_test.cpp
index ae584ac..12d4ac8 100644
--- a/null_stream_test.cpp
+++ b/null_stream_test.cpp
@@ -101,6 +101,28 @@ void mete_kuehl_static()
}
}
+// Test writing to local std::ostream(nullptr).
+
+void mete_local_ostream_0()
+{
+ for(int i = 0; i < 1e4; ++i)
+ {
+ std::ostream os(nullptr);
+ emit_text_to_stream(os);
+ }
+}
+
+// Test writing to "global" std::ostream(nullptr).
+
+void mete_global_ostream_0()
+{
+ std::ostream os(nullptr); // as if global
+ for(int i = 0; i < 1e4; ++i)
+ {
+ emit_text_to_stream(os);
+ }
+}
+
/// Test writing to an unopened ofstream.
void mete_unopened_fstream()
@@ -207,6 +229,8 @@ void assay_speed()
<< "\n Kühl : " << TimeAnAliquot(mete_kuehl)
<< "\n Kühl, badbit : " << TimeAnAliquot(mete_badbit_kuehl)
<< "\n Kühl, static : " << TimeAnAliquot(mete_kuehl_static)
+ << "\n global ostream(0): " << TimeAnAliquot(mete_global_ostream_0)
+ << "\n local ostream(0) : " << TimeAnAliquot(mete_local_ostream_0)
<< "\n unopened fstream : " << TimeAnAliquot(mete_unopened_fstream)
<< "\n fstream, badbit : " << TimeAnAliquot(mete_badbit_fstream)
<< "\n sstream, badbit : " << TimeAnAliquot(mete_badbit_sstream)
- [lmi-commits] [lmi] master updated (7a6262f -> a102012), Greg Chicares, 2021/08/05
- [lmi-commits] [lmi] master 50c1d57 1/6: Don't write solve trace to statusbar, Greg Chicares, 2021/08/05
- [lmi-commits] [lmi] master 440c67d 2/6: Add a null_stream unit test, Greg Chicares, 2021/08/05
- [lmi-commits] [lmi] master 52456de 3/6: Demonstrate the speed advantage of 'badbit', Greg Chicares, 2021/08/05
- [lmi-commits] [lmi] master 048b2cc 4/6: Demonstrate a peril, Greg Chicares, 2021/08/05
- [lmi-commits] [lmi] master 4bc0910 5/6: Test std::ostream(nullptr) as well,
Greg Chicares <=
- [lmi-commits] [lmi] master a102012 6/6: Generally avoid using null_stream(), Greg Chicares, 2021/08/05