what is the fastest way to split a string with a delimiter into a vector/array with C/C++ and STL? The only limitation is that I don't want to use boost.
I already tried different approaches - including strtok and stringstream - but it's always terrible slow compared to Java String.split().
Note that I haven't benchmarked it, I thought I'd leave comparison up to you since it would make more sense to compare to your existing results. Don't forget to turn on your compiler's optimizations too.
Perhaps one of the experts around here could give a better, perhaps more low level approach that would be faster.
I tried NwN's Method and it seems a little faster, though it still takes about 30 seconds to split a string with 3.2 Million chars.
I tried the same in Java, and figured out that loading the string from a textfile takes much longer than in c++, but splitting is done in, well, less than 1/10 of a second. The string has to be represented in a special way when it's loaded, right? I mean, all the splitting algorithms I tried don't even come close to this performance.
I don't have the time to give you exact benchmarks right now, but I'll do them when I get home today and let you know.
From other articles, it seems like ropes only become beneficial when used on large strings, so it seems (like usual) there is no "one fastest way", it depends on the size of string you're intending to split.
+1 on the tip with the rope! This really makes
sense now. What a pitty that there is no STL rope.
Would be a really great feature in C++ because the performance increase is really noticeable on large strings (see my last post above).