Below is my current char* to hex string function. I wrote it as an exercise in bit manipulation. It takes ~7ms on a AMD Athlon MP 2800+ to hexify a 10 million byte array. Is
not going to make a lot of difference... *pChar-(ofs*16) can be done with [*pCHar & 0x0F]
I'm not sure doing it more bytes at a time will be better... you'll probably just get tons of cache misses and slow it down significantly.
What you might try is to unroll the loop though, take larger steps and do more characters each time through the loop, to remove some of the loop overhead.
Make sure your compiler optimization is turned on to the highest working level.
You know, flags like '-O1' to '-03' in gcc.
For one, instead of multiplying by 16
do a bitshift << 4
Also don't use the std::string
, instead just create a buffer on the heap and then delete
it. It will be more efficient than the object destruction that is needed from the string.