public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/44510]  New: stream unformatted inserter is slower than formatted inserter
@ 2010-06-13  1:44 liugavin at hotmail dot com
  2010-06-13 12:13 ` [Bug libstdc++/44510] " paolo dot carlini at oracle dot com
  0 siblings, 1 reply; 2+ messages in thread
From: liugavin at hotmail dot com @ 2010-06-13  1:44 UTC (permalink / raw)
  To: gcc-bugs

the run times has 2 times difference( formatted one FASTER than unformatted ).
[ compile option -O3 ]

void test_stream_inserter()
{
    int a = 1111;
    std::stringstream is;
    for( unsigned int i=0; i<1024*1024*100; ++i )
      {
        void* pa = ((void*)&a);
        void** pb = &pa;
#ifdef FORMATTED
        is << pb;
        is >> pa;
#else
        is.write( (const char*)pb, sizeof(pb) );
        is.read( (char*)pb, sizeof(pb) );
#endif
      }
}


-- 
           Summary: stream unformatted inserter is slower than formatted
                    inserter
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: liugavin at hotmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44510


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/44510] stream unformatted inserter is slower than formatted inserter
  2010-06-13  1:44 [Bug libstdc++/44510] New: stream unformatted inserter is slower than formatted inserter liugavin at hotmail dot com
@ 2010-06-13 12:13 ` paolo dot carlini at oracle dot com
  0 siblings, 0 replies; 2+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-06-13 12:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paolo dot carlini at oracle dot com  2010-06-13 12:12 -------
First, note that the *extractor*, ie, read, is slower, not the inserter. That
said, I think it's not at all obvious that read must be faster than the pointer
extractor, because in the latter case the parsing itself is a bit slower but
then the result can be copied 8 bytes at once as a builtin pointer type.
Barring quite sophisticated compiler optimizations, in general this is not the
case for read. In fact, other completely unrelated implementations of the
runtime library, eg in SunStudio, also have the formatted case faster than the
unformatted, for this example. That said, I think we have some potential margin
of improvement with a patch like the one I'm attaching below. Please try it out
and let me know how it goes (in case some tweaks will be also needed to the
exports, minor issues):

Index: sstream
===================================================================
--- sstream     (revision 160663)
+++ sstream     (working copy)
@@ -219,6 +219,13 @@
       seekpos(pos_type __sp,
              ios_base::openmode __mode = ios_base::in | ios_base::out);

+      virtual streamsize
+      xsgetn(char_type* __s, streamsize __n)
+      {
+       _M_update_egptr();
+       return __streambuf_type::xsgetn(__s, __n);
+      }
+
       // Internal function for correctly updating the internal buffer
       // for a particular _M_string, due to initialization or re-sizing
       // of an existing _M_string.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-06-13 12:12:57
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44510


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-06-13 12:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-13  1:44 [Bug libstdc++/44510] New: stream unformatted inserter is slower than formatted inserter liugavin at hotmail dot com
2010-06-13 12:13 ` [Bug libstdc++/44510] " paolo dot carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).