-1

There are a lot of different ways to convert a byte array to a hex string. What is the fastest way?

There are possibly more.

Community
  • 1
  • 1
dlanod
  • 8,664
  • 8
  • 54
  • 96

1 Answers1

5

Testing over 100,000 iterations found:

  1. the lookups solution took 63 ms.
  2. the sprintf solution took 827 ms (~10x more than #1).
  3. the stringstream solution took 1684 ms (~25x more than #1).

All results from my own test system.

This is probably a surprise to no one very familiar with C and C++ but given the number of different approaches available for solving this problem, having a Q&A on the approach with the best performance could be useful for people less familiar with C/C++.

dlanod
  • 8,664
  • 8
  • 54
  • 96