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

A

ai@work

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
 
M

Mike Wahler

ai@work said:
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
 
A

Alf P. Steinbach

* 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... ;-)
 
J

Jonathan Turkanis

ai@work said:
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
 
A

ai@work

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 .
 
J

Jonathan Turkanis

ai@work said:
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
 
A

ai@work

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;
}
 
T

Tom Widmer

ai@work said:
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
 
R

Ron Natalie

ai@work said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top