| | |
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:
Solved Threads: 0
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
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
•
•
Join Date: Jun 2009
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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 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.
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.
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.
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.
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
(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
•
•
Join Date: Aug 2008
Posts: 149
Reputation:
Solved Threads: 8
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.
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.
![]() |
Similar Threads
- C++: ifstream file pointer not getting reset (C++)
- problems with reading random access line from a file (C++)
- fstream Tutorial (C++)
- Problem in creating efficient Log file (VB.NET)
- Which is faster.. javascript file or embedded? (ASP.NET)
- How to do 64bit fstream file access in Linux (C++)
- A question about file streaming (C++)
- fstream.h, I thought it was a standard header.... (C++)
- File processing problem (C++)
- writing a script (Shell Scripting)
Other Threads in the C++ Forum
- Previous Thread: Shut Down function not working
- Next Thread: LinKer Error for Static Function
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






