This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: libstdc++/2211: Performance regression for cin.read with respect to g++-2.95.2 ?



bkoz@gcc.gnu.org said:
> Synopsis: Performance regression for cin.read with respect to
> g++-2.95.2 ?

> Responsible-Changed-From-To: unassigned->bkoz Responsible-Changed-By:
> bkoz Responsible-Changed-When: Tue Jun 26 17:19:30 2001
> Responsible-Changed-Why:
>     Mine. State-Changed-From-To: open->feedback State-Changed-By: bkoz
> State-Changed-When: Tue Jun 26 17:19:30 2001 State-Changed-Why:
>     I'm not quite sure if this is still an issue.
>          std::ios::sync_with_stdio(false)
>          will improve output performance.

> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2211&database=gcc 

Well not quite...
Here are the results before and after adding 
std::ios::sync_with_stdio(false);

vanuatu->cat toto toto | ./a.out ~/Robotvis++/Libs/Image/tests/images/scully.float.inr
Before ifstream::read: 993852954
After ifstream::read: 993852954
Before cin.read: 993852954
After cin.read: 993852960
Before fread: 993852960
After fread: 993852960

vanuatu->g++ Test.C
vanuatu->cat toto toto | ./a.out ~/Robotvis++/Libs/Image/tests/images/scully.float.inr
Before ifstream::read: 993853019
After ifstream::read: 993853020
Before cin.read: 993853020
After cin.read: 993853026
Before fread: 993853026
After fread: 993853026

Just in case the code of Test.C with sync_with_stdio is:

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <time.h>

int
main(int argc,char *argv[])
{
    const unsigned data_size = 1367160;
    char data[data_size];

    std::ifstream ifs(argv[1]);
    std::ios::sync_with_stdio(false);

    std::cerr << "Before ifstream::read: " << time(0) << std::endl;
    ifs.read(data,data_size);
    std::cerr << "After ifstream::read: " << time(0) << std::endl;

    std::cerr << "Before cin.read: " << time(0) << std::endl;
    std::cin.read(data,data_size);
    std::cerr << "After cin.read: " << time(0) << std::endl;

    std::cerr << "Before fread: " << time(0) << std::endl;
    fread(data,1,data_size,stdin);
    std::cerr << "After fread: " << time(0) << std::endl;
}

So basically I see no improvement (this is gcc version 3.1 20010617 ).
I have to bootstrap a new compiler to get results with a more recent 
compiler.

I really believe that the read/write operations should use the buffer 
as discussed in the mailing list a few days ago (ie avoid character 
per character write). If this is what sync_with_stdio is supposed to 
give as a side effect, I do not see it. I must add that I dislike
the sync_with_stdio trick should it have worked because it's 
unnatural. People expect a lot of thing from C++ IO (to be in sync 
with stdio is one of course, but faster (or at least as 
fast as) IO than C is another). And obviously this is conflicting for
the time being.

I can investigate how to implement the scheme Carlo sketched (IIRC) if
you want so (but it will not be before 3 weeks, as I'm leaving for that period of time).

Long term, I'd like to understand...
Are you still aiming at the libio version or is this completely damped.
Can it correct this bufferng problem ?

	Thank's 

	Theo.

--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
 --------------------------------------------------------------------


PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]