stringstream slowness

Radu Grigore radugrigore@gmail.com
Tue Jun 22 09:21:00 GMT 2004


A program like the following works about 3 times faster when compiled
with VS7.1, compared to gcc3.3.1. The optimizations are turned on (-O2
for gcc and "release" mode for VS).

#include <sstream>

using namespace std;

void f(vector<string> v)
{
   for (int i = 0; i < int(v.size()); ++i)
   {
       istringstream iss(v[i]);
       int a, b, c, d, e;
       iss >> a >> b >> c >> d;
       /* do something with a, b, c, d, e */
   }
}

int main()
{
   string v[] = {"1 2 3 4 5", "101 102 200 203 205" 
      /* add  lots of others strings like these */ };
    f(vector<string>(v, v + sizeof(v)/sizeof(v[0])));
}

PS: I am not subscribed to the list



More information about the Libstdc++ mailing list