Quote:Original post by KulSeran
1) I think you mean miliseconds (GetTickCount isn't nanoseconds)
My intention was : GetTickCount is miliseconds and since the program loops 1,000,000 times, the time measured by GetTickCount() becomes nanoseconds for one iteration. I'm too lazy to write
printf( "%f ns\n", uElapsed / 1000.0 / 1000000 /*# of iterations*/ * 1E+9 /**/ );
Quote:
2) you can always call std::string::reserve if you know you are doing a lot of
concatanations (equivelent to your wonderful buf[21] trick)
But in my opinion std::string::reserve() allocates the buffer from the heap and that's still not the same.
BTW, your word "wonderful trick" made me laugh a lot.
Quote:
3) If string are you bottleneck, and you don't NEED strings, you may as well replace them with something like CRC hashes of the strings in question.
4) If you do NEED string, you may want to rethink your algorithm anyway. Lots of temporary copies and concatenations
can be a sign of you doing it wrong to start with. Changing how you make you pass over the dataset can mean that you
don't even need to be making copies of anything.
I saw some sources written in Java and was shocked at that it's pretty fast despite of a lot of string operations. And yes, one can always optimize algorithms to minimize string operations. I'm kind of lazy in that sense. I always think about 'how to make good things without headache'.
Quote:
5) get a custom allocator for the string, especially if you know you are going to be allocating many small strings.
Could you recommend me some? I'd like to look at them so that I can optimize my heap allocator further.
Quote:You have to remember that std::blah is a GENERAL PURPOSE tool. You can always speed it up by giving it knowledge about the
current situation you are using it in. And you can probably write a faster SINGLE PURPOSE tool, but you have to weigh in the cost
of time spent on your tool vs. just using a proven library.
Thanks. Fortunately this case seems to me profitable. I think the heap I'm making now can be used for other purposes also.
And rating you up for giving many ideas