Saturday, December 4, 2010

istreambuf_iterator

The following call is about 40% faster than the next:

copy(istreambuf_iterator<string>( myInputFileStream ),
     istreambuf_iterator<string>(),
     back_inserter(v));

copy(istream_iterator<string>( myInputFileStream ),
     istream_iterator<string>(),
     back_inserter(v));

The reason why it is faster, is that it does not do a lot of checking, and it also uses the rdbuf() member function directly, dealing with characters of type char or wchar_t.

istream_iterator<> uses operator>>().

No comments:

Post a Comment