472,373 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

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

ai
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

Jul 22 '05 #1
9 2253

"ai@work" <tg*******@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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
Jul 22 '05 #2
* 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?
Jul 22 '05 #3
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

Jul 22 '05 #4
ai
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 .

Jul 22 '05 #5
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
Jul 22 '05 #6
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

Jul 22 '05 #7
ai
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;
}

Jul 22 '05 #8
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
Jul 22 '05 #9
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.
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Juergen Marsch | last post by:
Hi, writing files > 2G with standard library iostream classes results in "... file size limit exeeded." Compiling my program with "-D_FILE_OFFSET_BITS=64" doesn't make any difference. If you...
4
by: aurgathor | last post by:
Howdy, What would be the equivalent of getch() using iostream? My current code is: cout << "\nPress <Enter> to continue..."; getch(); but <conio.h> is not kosher for the C++ class.
1
by: zerotyNONONOTHERESNOSPAMMING!type | last post by:
Hi, As most of you probably already know, depending on which implementation of C++ you have, #include <iostream> may cause various other headers to be #included too. (I've observed cstring,...
2
by: Brett | last post by:
Hi, I'm compiling an old project under the 'new' visual studio 7.1.3088. I changed the line: #include <iostream.h> to #include <iostream> and now I get a stack of errors, some of which...
1
by: Russell Mangel | last post by:
After creating a new .NET Class Library project, I then add the header file: #include <iostream> (I tried adding in my main .cpp file and also tried in stdafx.h file.) Doesn't work, and I...
9
by: nichas | last post by:
I tried to use #include<iostream> in visual C++ compiler but then it didnt work but i see this is the way it is being mentioned in C++ primer by lippman and lajoie.. where is the problem.. Do...
5
by: wesley | last post by:
Hi All. i am new to C++. I know that in order to use cout, i need to include <iostream>. I have done this, but i still get errors when i try to output to the screen. Is there a file that needs to...
1
by: lars.uffmann | last post by:
Hello everyone! I just debugged a pretty huge project, eliminating basically every memory leak that would occur with the current configuration files, at least according to the mtrace() tool from...
1
by: Old Wolf | last post by:
In a discussion elsewhere, someone wrote: #include <iostreamis not guaranteed to define std::cout, it merely has to declare it as an extern object, and declarations of extern objects do not...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.