 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alex Vinokur Guest
|
Posted: Wed Oct 22, 2003 6:13 pm Post subject: Classic and standard iostreams |
|
|
Technical Report on C++ Performance
ISO/IEC PDTR 18015; Date: 2003-08-11; WG21 N1487=03-0070
* http://std.dkuug.dk/JTC1/SC22/WG21/docs/PDTR18015.pdf
* http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1487.pdf
Appendix D: Timing Code
D.5 Measuring the Cost of Synchronized I/O
<QUOTE>
Test program to
(1) compare the performance of classic iostreams,
standard iostreams, and C-style stdio for output, and
(2) test any overhead of sync_with_stdio(true). Standard
iostreams by default are synchronized with stdio streams;
the opposite was true of classic iostreams.
optional command line argument:
- how many numbers to output (default 1,000,000)
- name of output file (default cout)
When compiling, define CLASSIC or STDIO to enable
those options; otherwise the default is to use
standard iostreams.
#if defined (STDIO)
#include <stdio.h>
#elif defined (CLASSIC)
#include <iostream.h>
#include <fstream.h>
#else
#include <iostream> // use standard iostreams
#include <fstream>
using namespace std;
#endif
</QUOTE>
Here are two programs which use classic and standard iostreams.
One can see that GNU g++ compiler generates the same code for both programs.
Is there any situation that different assembly code is generated while using classic and standard iostreams ?
====== foo1.cpp ======
// classic iostreams
#include <iostream.h>
int main ()
{
cout.sync_with_stdio (false);
cout << 123 << endl;
cout.sync_with_stdio (true);
cout << 456 << endl;
return 0;
}
======================
====== foo2.cpp ======
// standard iostreams
#include
using namespace std;
int main ()
{
cout.sync_with_stdio (false);
cout << 123 << endl;
cout.sync_with_stdio (true);
cout << 456 << endl;
return 0;
}
======================
====== Compilation & Comparison ======
$ g++ -Wno-deprecated -save-temps foo1.cpp
$ g++ -save-temps foo2.cpp
$ diff foo1.s foo2.s
1c1
< .file "foo1.cpp"
---
======================================
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
P.J. Plauger Guest
|
Posted: Wed Oct 22, 2003 8:04 pm Post subject: Re: Classic and standard iostreams |
|
|
"Alex Vinokur" <alexvn (AT) bigfoot (DOT) com> wrote
| Quote: | Here are two programs which use classic and standard iostreams.
One can see that GNU g++ compiler generates the same code for both programs.
Is there any situation that different assembly code is generated while using classic and standard
iostreams ? |
Yes.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Alex Vinokur Guest
|
Posted: Thu Oct 23, 2003 3:54 pm Post subject: Re: Classic and standard iostreams |
|
|
"P.J. Plauger" <pjp (AT) dinkumware (DOT) com> wrote
| Quote: | "Alex Vinokur" <alexvn (AT) bigfoot (DOT) com> wrote in message
news:bn5icr$tjrn2$1 (AT) ID-79865 (DOT) news.uni-berlin.de...
Here are two programs which use classic and standard iostreams.
One can see that GNU g++ compiler generates the same code for both programs.
Is there any situation that different assembly code is generated while using classic and standard
iostreams ?
Yes.
|
Is it possible that 'classic and standard iostreams from testsuites "D.5
Measuring the Cost of Synchronized I/O" (see Technical
Report on C++ Performance)' have different behavior from this point of view?
It seems that their assembly code is identical (while using GNU g++ 3.3.1).
--
=====================================
Alex Vinokur
mailto:alexvn (AT) connect (DOT) to
http://mathforum.org/library/view/10978.html
news://news.gmane.org/gmane.comp.lang.c++.perfometer
=====================================
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Thu Oct 23, 2003 9:20 pm Post subject: Re: Classic and standard iostreams |
|
|
"Alex Vinokur" <alexvn (AT) bigfoot (DOT) com> wrote
| Quote: | Technical Report on C++ Performance
ISO/IEC PDTR 18015; Date: 2003-08-11; WG21 N1487=03-0070
* http://std.dkuug.dk/JTC1/SC22/WG21/docs/PDTR18015.pdf
* http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1487.pdf
Appendix D: Timing Code
D.5 Measuring the Cost of Synchronized I/O
QUOTE
Test program to
(1) compare the performance of classic iostreams,
standard iostreams, and C-style stdio for output, and
(2) test any overhead of sync_with_stdio(true). Standard
iostreams by default are synchronized with stdio streams;
the opposite was true of classic iostreams.
optional command line argument:
- how many numbers to output (default 1,000,000)
- name of output file (default cout)
When compiling, define CLASSIC or STDIO to enable
those options; otherwise the default is to use
standard iostreams.
#if defined (STDIO)
#include <stdio.h
#elif defined (CLASSIC)
#include
#include
#else
#include
#include
using namespace std;
#endif
/QUOTE
Here are two programs which use classic and standard iostreams.
One can see that GNU g++ compiler generates the same code for both
programs.
|
Which version of g++. G++ pre-3.0 didn't have an implementation of
standard iostream, and g++ 3.0 and beyond don't have an implementation
of the classic iostreams. This means the programs which worked with g++
pre-3.0 either fail to compile, or worse, have subtly different
semantics with newer versions of the compiler, but this doesn't seem to
bother the people at g++. Nor at Sun, since they follow the same policy
(with the additional problem that their implementation of the standard
iostream is simply to slow to be usable in real programs).
Microsoft got it right (except that at least in VC++ 6.0, the
xalloc/iword/pword mecahnism doesn't work in the classical iostream); I
don't know why it is so difficult for the others.
| Quote: | Is there any situation that different assembly code is generated while
using classic and standard iostreams ?
|
Always, provided the compiler provides both. The semantics are subtly
different, so the assembler code must be different.
Simply exposing the standard iostream in the global namespace is NOT
providing classical iostream.
--
James Kanze GABI Software mailto:kanze (AT) gabi-soft (DOT) fr
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|