How to perform fast formatted input from a stream in C ++?

The situation is this: there is a file with 14,294,508 unsigned integers and 13,994,397 floating point numbers (you must read doubles). The total file size is ~ 250 MB.

Usage std::istreamtakes ~ 30 seconds. Reading data from a file to memory (just copying bytes without formatted input) is much faster. Is there a way to improve read speed without changing the file format?

+5
source share
5 answers

Do you need to use the STL input style? You should check out this excellent job from one of the experts. It is specialized iostreamfrom Dietmar Kuhl.

I hate to suggest this, but look at the I / O routines formatted in C. Also, do you read the whole file in one go?

+3
source

You can also see Matthew Wilson's FastFormat library:

I have not used it, but it makes some pretty impressive statements, and I found many of my other works that are worth exploring and using (and sometimes stealing).

+1
source

. , .

, , , , , . , , , . .

+1

(atoi atof), , "" .

+1

- - ++, :

#include <sstream>
// Load file into string file_string
std::stringstream s( file_string );
int x; float y;
s >> x >> y;

( , iostreams), , .

0

All Articles