is MS newer <iostream> is slower than older <iostream.h>?

Discussion in 'C++' started by ai@work, Dec 15, 2004.

  1. ai@work

    ai@work Guest

    Hi ,

    I have an application which has to read files of size few mba nd read
    them into array . Since i am using STL and std namespace to avoid the
    error


    error C2872: 'ifstream' : ambiguous symbol

    when i include <iostream.h> with std namespace and <List>

    however the new <iostream> library seems to be atleast 20-25 slower
    than <isotream.h> .

    any ideas?how i can use old <iostream.h> with STL?
    thanks in advance
    Giri
     
    ai@work, Dec 15, 2004
    #1
    1. Advertising

  2. ai@work

    Mike Wahler Guest

    "ai@work" <> wrote in message
    news:...
    > Hi ,
    >
    > I have an application which has to read files of size few mba nd read
    > them into array . Since i am using STL and std namespace to avoid the
    > error
    >
    >
    > error C2872: 'ifstream' : ambiguous symbol
    >
    > when i include <iostream.h> with std namespace and <List>
    >
    > however the new <iostream> library seems to be atleast 20-25 slower
    > than <isotream.h> .
    >
    > any ideas?how i can use old <iostream.h> with STL?


    <iostream.h> is not and has never been part of ISO standard
    C++, which is the only topic here. If you want to learn
    more details about the Microsoft compiler and how to make
    it do what you want, try a Microsoft group. The C++ language
    makes no requirements about execution speed.

    -Mike
     
    Mike Wahler, Dec 15, 2004
    #2
    1. Advertising

  3. * ai@work:
    >
    > I have an application which has to read files of size few mba nd read
    > them into array . Since i am using STL and std namespace to avoid the
    > error
    >
    >
    > error C2872: 'ifstream' : ambiguous symbol
    >
    > when i include <iostream.h> with std namespace and <List>
    >
    > however the new <iostream> library seems to be atleast 20-25 slower
    > than <isotream.h> .


    Some measurements were published in DDJ (or perhaps it was CUJ)
    a year or two or three ago, and you're right: in general, no matter
    which C++ implementation, the pre-standard iostreams <iostream.h>
    are much faster than <iostream>; then again, C library i/o is much
    faster than iostreams; and native OS i/o is much faster yet (here
    we may be talking orders of magnitude, not just a trivial factor of
    2 or something).


    > any ideas?how i can use old <iostream.h> with STL?


    In general you can't, because the pre-standard iostreams _were_
    what we had before the standard, so in contrast to other libraries
    they are very likely to conflict at some basic level with use of
    the real standard library, e.g., tool assumptions.

    Consider using _anything_ other than iostreams for serious work.
    Or, if you feel adventurous, check out YASLI, the not-quite-mythical
    efficient standard library implementation that Andrei may or may
    not be the secret mastermind of. I haven't checked that, yet... ;-)

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Dec 15, 2004
    #3
  4. ai@work wrote:
    > Hi ,
    >
    > I have an application which has to read files of size few mba nd read
    > them into array . Since i am using STL and std namespace to avoid the
    > error


    > however the new <iostream> library seems to be atleast 20-25 slower
    > than <isotream.h> .


    Could you post the part of your code which reads the file into an array? I'm
    interested to see what kind of code yields these performance differences.

    Jonathan
     
    Jonathan Turkanis, Dec 15, 2004
    #4
  5. ai@work

    ai@work Guest

    Re: is MS newer <iostream> is slower than older <iostream.h>?

    Thanks everyone for their wonderful inputs. As Mr Alf P. Steinbach
    pointed out I used stdio.h and it turned out to be faster than
    iostream.h .

    The code i used is

    #include<iostream.h>
    ifstream os("filename.txt");
    for( i=o;i < lines;i++)
    os>>variable;

    The problem was if i change #include<iostream.h> to #include<iostream>
    it runs very slow on MS . However linux i dont see much change .
     
    ai@work, Dec 15, 2004
    #5
  6. Re: is MS newer <iostream> is slower than older <iostream.h>?

    ai@work wrote:
    > Thanks everyone for their wonderful inputs. As Mr Alf P. Steinbach
    > pointed out I used stdio.h and it turned out to be faster than
    > iostream.h .
    >
    > The code i used is
    >
    > #include<iostream.h>
    > ifstream os("filename.txt");
    > for( i=o;i < lines;i++)
    > os>>variable;
    >
    > The problem was if i change #include<iostream.h> to #include<iostream>
    > it runs very slow on MS . However linux i dont see much change .


    I don't quite understand your code, because it seems to be reading each
    character from the file into the same variable.

    In general, if you don't need to take advantage of formatting, you should use
    the unformatted input functions of ifstream, or switch to filebuf. E.g.,

    char buf[N];
    ifstream is("filename.txt", ios::in, ios::binary);
    streamsize amt = is.read(buf, N);

    Or

    char buf[N];
    filebuf fb;
    fb.open("filename.txt", ios::in, ios::binary);
    streamsize amt = is.sgetn(buf, N);

    I'd be surpised if using <iostream.h> or <cstdio> performed noticeably better.

    Jonathan
     
    Jonathan Turkanis, Dec 16, 2004
    #6
  7. Re: is MS newer <iostream> is slower than older <iostream.h>?

    Jonathan Turkanis wrote:

    Some typos:

    > ifstream is("filename.txt", ios::in, ios::binary);


    > fb.open("filename.txt", ios::in, ios::binary);


    The second comma on each line above should be a bitwise OR.

    > Jonathan
     
    Jonathan Turkanis, Dec 16, 2004
    #7
  8. ai@work

    ai@work Guest

    Re: is MS newer <iostream> is slower than older <iostream.h>?

    I'm sorry for the incomplete code. I am reading the whole file (abt a
    million lines)into an list of class.

    The actual code now is .(which is much much faster than prevous by
    order of 20 -25)

    while ((!fp == NULL) && (count_profs < MAX_PRO_DIM))
    {

    fscanf(fp ,"%d %d %d",&len,&lindex,&loffset);

    if (!len) break;
    hi=hash(loffset);
    temp.set ( count_dims , lindex ,loffset,len);
    buckets[hi].profiles.push_back (temp);
    count_profs ++;
    buckets[hi].count ++;
    len = 0;
    }

    previous code was

    while ((!os.eof()) && (count_profs < MAX_PRO_DIM))
    {
    os>>len>>lindex>>loffset;
    if (!len) break;
    hi=hash(loffset);
    temp.set ( count_dims , lindex ,loffset,len);
    buckets[hi].profiles.push_back (temp);
    count_profs ++;
    buckets[hi].count ++;
    len = 0;
    }
     
    ai@work, Dec 16, 2004
    #8
  9. ai@work

    Tom Widmer Guest

    Re: is MS newer <iostream> is slower than older <iostream.h>?

    ai@work wrote:
    > I'm sorry for the incomplete code. I am reading the whole file (abt a
    > million lines)into an list of class.
    >
    > The actual code now is .(which is much much faster than prevous by
    > order of 20 -25)


    How do you open the file in the iostreams code? 20-25 sounds too great a
    difference to me, unless you are doing something wrong (or the library
    has a buffering bug, such as the VC6 one).

    Also, why is your input stream called os?

    Tom
     
    Tom Widmer, Dec 16, 2004
    #9
  10. ai@work

    Ron Natalie Guest

    Re: is MS newer <iostream> is slower than older <iostream.h>?

    ai@work wrote:
    > Thanks everyone for their wonderful inputs. As Mr Alf P. Steinbach
    > pointed out I used stdio.h and it turned out to be faster than
    > iostream.h .
    >


    Are you running in release mode? Timings of Visual Studio (and many
    other compilers) are useless in debug mode because a substantial amount
    of optimization, especially the inlining of small functions inside the
    library function implementations is disabled.
     
    Ron Natalie, Dec 16, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stan Goodman

    Even older fart, even newer newbie

    Stan Goodman, Jul 3, 2003, in forum: Java
    Replies:
    11
    Views:
    701
    Stan Goodman
    Jul 4, 2003
  2. Replies:
    2
    Views:
    429
  3. Andre Charbonneau

    XPath queries getting slower and slower...

    Andre Charbonneau, Feb 15, 2005, in forum: Java
    Replies:
    0
    Views:
    550
    Andre Charbonneau
    Feb 15, 2005
  4. Mark
    Replies:
    20
    Views:
    1,648
    Dave O'Hearn
    Dec 27, 2004
  5. Jorge Godoy
    Replies:
    11
    Views:
    539
    Peter Hansen
    Jul 9, 2004
Loading...

Share This Page