Which is faster/more efficient c++´s fstream, or c's FILE

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 2
Reputation: george_cpp is an unknown quantity at this point 
Solved Threads: 0
george_cpp george_cpp is offline Offline
Newbie Poster

Which is faster/more efficient c++´s fstream, or c's FILE

 
0
  #1
Jun 17th, 2009
Hi All,

Does anyone know which file manipulation library is faster between c's FILE and c++'s fstream?

I would suppose that c++'s fstream would be the faster but I just wanted to see some expert advice/opinion on this.

I googled the internet without finding anything concrete.

If there is any existing thread on this I would appreciate if you could post it here so I can take a look.

Thanks for your help
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,706
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 731
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Which is faster/more efficient c++´s fstream, or c's FILE

 
3
  #2
Jun 17th, 2009
On current implementations, you'll probably find that the stdio library is faster than the iostream library. The usual recommendation is to try both and use the one that's fastest on your setup, if all you care about is execution performance.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: george_cpp is an unknown quantity at this point 
Solved Threads: 0
george_cpp george_cpp is offline Offline
Newbie Poster

Re: Which is faster/more efficient c++´s fstream, or c's FILE

 
0
  #3
Jun 17th, 2009
Originally Posted by Narue View Post
On current implementations, you'll probably find that the stdio library is faster than the iostream library. The usual recommendation is to try both and use the one that's fastest on your setup, if all you care about is execution performance.
Thanks Narue,

I will try to make a test using timers for both once I have the time, Ill post the results with some code for any interested readers when I do.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Which is faster/more efficient c++´s fstream, or c's FILE

 
4
  #4
Jun 17th, 2009
Except which one is "fastest on the current setup" is a moving goalpost with every patch / update / release / new compiler.

Plus if you're writing code which is in any way open source, then a whole raft of different compiler options will appear, each with their own "x is faster than y by z%" metrics.

If you don't already have any need for any C I/O, then you might avoid some code bloat by not dragging in libraries which you're not making a great deal of use of already, for what may be a marginal benefit.

File I/O is terribly slow anyway. You might want "cheetah", but all you've got is a choice between "snail" and "tortoise".

Here's an example. If your C++ I/O takes 1 hour, and your C I/O takes 50 minutes, there isn't any point in making the change. Your users are NOT going to come back from lunch 10 minutes earlier due to your efficiency.

Likewise, if it's around 10 minutes, then a few minutes either way won't get them back from the coffee break any time sooner.

If you're going to do it, one of the methods needs to break through a time barrier where your users would figure out they could go and do something more productive while your program was running.

An hour to a minute say needs a change of algorithm, not a change of I/O library.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 793
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: Which is faster/more efficient c++´s fstream, or c's FILE

 
1
  #5
Jun 17th, 2009
Oh please. Micro-optimization is not cool. Adhere to the philosophy that "Developers time is far far more important than machine time"
Small optimization won't make significant changes in the execution but will drastically increase your head ache.
I find Salem post to be extremely right in this regard. Very well said.
My advice is : use the one which will save you headache while debugging a month( or perhaps a fortnight) later.


>if it's around 10 minutes, then a few minutes either way won't get them back
>from the coffee break any time sooner.
I can have two cups in those 10 minutes.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 149
Reputation: monkey_king is on a distinguished road 
Solved Threads: 8
monkey_king monkey_king is offline Offline
Junior Poster

Re: Which is faster/more efficient c++´s fstream, or c's FILE

 
0
  #6
Jun 17th, 2009
I think it depends on what you are doing with the file.
I've found that the FILE, strtok is by far the fastest way of reading in data.
I've been using flat files, (same number of columns in all lines).
On the scale of several gigabytes.

And avoiding the c++ streams was faster.
But I've heard rumors that you can tweak the fstream with a fsetbuf,
that should make it faster.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC