C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

stringstream (binary) performance problem

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Remo Eichenberger
Guest





PostPosted: Sat Sep 13, 2003 11:48 pm    Post subject: stringstream (binary) performance problem Reply with quote



(first sorry for my bad english)

i have a big performance problem with following (the file is 354KB):

my environment:
vc6 sp5
2.4 ghz P4
512 MB RAM

code:

fstream f("file",ios_base::in | ios_base::out | ios_base::binary);
stringstream ss;
ss << f.rdbuf();

this code use 6 seconds to finish !! this is very very slow.

i tryed many different methods:

1)

fstream f("file",ios_base::in | ios_base::out | ios_base::binary);
istream::pos_type size = stream_size(f);

string buffer;
buffer.reserve(size);
istream_iterator copy(f_iter, istream_iterator<char>(),buffer.begin());

this use 0.057 seconds

2)

fstream f("file",ios_base::in | ios_base::out | ios_base::binary);
vector<char> buffer;
istream_iterator<char> f_iter(f);
copy(f_iter, istream_iterator<char>(),back_insert_iterator< vector
Quote:
( buffer ));

this use 0.072

3) the fastest

fstream f("file",ios_base::in | ios_base::out | ios_base::binary);
istream::pos_type size = stream_size(f);
char* buffer = new char[size];
f.read(buffer,size);
delete [] buffer;

this use 0.007 seconds.

i found that the performance problem is the minimum allocation-size in the
implementation of basic_streambuf from Dinkumware. This is 32 byte !? when i
use a my patched streambuf (65535) and insert this in the stringstream then
the first example use 0.055 second !

my question:

1) what is the "correct" and "stl-like" way to solve this performance
problem without changing the interface of the sstream ? ( i don't wan't use
static array c-style)
2) is the following code correct to inject the patched streambuf ?

basic_stringbufx< char, char_traits strbufx;
stringstream ss;
ss.ostream::rdbuf(&strbufx);
ss << f.rdbuf();

thanks for your input

Remo Eichenberger

btw. the vc7.1 - compiler optimize the first sample and has 0.01 second !!
:-)



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
White Wolf
Guest





PostPosted: Sun Sep 14, 2003 1:41 am    Post subject: Re: stringstream (binary) performance problem Reply with quote



Remo Eichenberger wrote:
Quote:
(first sorry for my bad english)

i have a big performance problem with following (the file is 354KB):

my environment:
vc6 sp5
2.4 ghz P4
512 MB RAM

code:

fstream f("file",ios_base::in | ios_base::out | ios_base::binary);
stringstream ss;
ss << f.rdbuf();

this code use 6 seconds to finish !! this is very very slow.
[SNIP]
1) what is the "correct" and "stl-like" way to solve this performance
problem without changing the interface of the sstream ? ( i don't
wan't use static array c-style)

IMO first is to go to the Dinkumware site and check out if your header is
patched:
http://www.dinkumware.com/vc_fixes.html

Look for fstream and see the fix for a _performance_ issue. It might be the
thing you are looking for.

I think it is worth to read through that page (if you still have to use a
compiler from the previous millenia Wink ) and apply those fixes which might
matter.

--
WW aka Attila



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Stephen Howe
Guest





PostPosted: Sun Sep 14, 2003 11:23 am    Post subject: Re: stringstream (binary) performance problem Reply with quote



Quote:
this code use 6 seconds to finish !! this is very very slow.

I think your basic problem is the slow stringstream. Go to
http://www.dinkumware.com/vc_fixes.html

and apply the sstream patch (and apply the others).

Note: These patches never made it into any of Microsoft's SP's for VC++ 6.0

For VC++ 7.1, Microsoft have had a change of policy and any fixes to
Dinkumware's files will be in SP's for 7.1.
That is better news for C++ programmers using this compiler.

Stephen Howe



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ulrich Eckhardt
Guest





PostPosted: Sun Sep 14, 2003 11:24 am    Post subject: Re: stringstream (binary) performance problem Reply with quote

Remo Eichenberger wrote:
[bad performance of VC6's native stringstreams]

Try switching to STLport([url]www.stlport.org)[/url], it is free and much more
performant, and it has an active forum where you can get help with
problems.

See also the thread "how do i create a ostringstream with pre-allocated
memory buffer", it also offers a possible solution to your problem.

Uli

--
Questions ?
see C++-FAQ Lite: http://parashift.com/c++-faq-lite/ first !


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Francis Glassborow
Guest





PostPosted: Sun Sep 14, 2003 1:33 pm    Post subject: Re: stringstream (binary) performance problem Reply with quote

In article <3f63f2a0$0$272$cc9e4d1f (AT) news (DOT) dial.pipex.com>, Stephen Howe
<NOSPAMsjhowe (AT) dial (DOT) pipex.com> writes
Quote:
I think your basic problem is the slow stringstream. Go to
http://www.dinkumware.com/vc_fixes.html

and apply the sstream patch (and apply the others).

Note: These patches never made it into any of Microsoft's SP's for VC++ 6.0

For VC++ 7.1, Microsoft have had a change of policy and any fixes to
Dinkumware's files will be in SP's for 7.1.
That is better news for C++ programmers using this compiler.

You imply that the failure to provide updates to the Library files was a
matter of policy. I am all in favour of placing blame on implementors
when they deserve it but as I understand it neither Dinkumware nor
Microsoft were responsible for the failure to include updates to the
library in VC++ 6.0. For most of the period covered by VC++ 6.0 there
was legal action involving Dinkumware but not MS one consequence of
which was that Dinkumware was prohibited from licensing updates for
redistribution. MS was an innocent bystander.


--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Remo Eichenberger
Guest





PostPosted: Wed Sep 17, 2003 9:43 am    Post subject: Re: stringstream (binary) performance problem Reply with quote

"White Wolf" <wolof (AT) freemail (DOT) hu> wrote

Quote:
Remo Eichenberger wrote:
(first sorry for my bad english)

i have a big performance problem with following (the file is 354KB):

my environment:
vc6 sp5
2.4 ghz P4
512 MB RAM

code:

fstream f("file",ios_base::in | ios_base::out | ios_base::binary);
stringstream ss;
ss << f.rdbuf();

this code use 6 seconds to finish !! this is very very slow.
[SNIP]
1) what is the "correct" and "stl-like" way to solve this performance
problem without changing the interface of the sstream ? ( i don't
wan't use static array c-style)

IMO first is to go to the Dinkumware site and check out if your header is
patched:
http://www.dinkumware.com/vc_fixes.html

Look for fstream and see the fix for a _performance_ issue. It might be the
thing you are looking for.

I think it is worth to read through that page (if you still have to use a
compiler from the previous millenia Wink ) and apply those fixes which might
matter.

hi

thanks for info, but i have allready tryed the newest dinkumware-stl for vc6
(3.0Cool. but this don't fix the problem. i found another performance problem
in ostream<<(streambuf*). this use sgetc/sputc and not sgetn/sputn.

Remo

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.