char[] to hex string exercise

前端 未结 16 741
感情败类
感情败类 2021-01-12 19:14

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

相关标签:
16条回答
  • 2021-01-12 20:05

    not going to make a lot of difference... *pChar-(ofs*16) can be done with [*pCHar & 0x0F]

    0 讨论(0)
  • 2021-01-12 20:08

    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.

    0 讨论(0)
  • 2021-01-12 20:09

    Make sure your compiler optimization is turned on to the highest working level.

    You know, flags like '-O1' to '-03' in gcc.

    0 讨论(0)
  • 2021-01-12 20:13

    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.

    0 讨论(0)
提交回复
热议问题