Benchmarks of various methods of conversion of long hexadecimal strings into binary data.
One of problems I recently face is the necessity of processing large amount of incoming data in form of hexadecimal strings which need to be converted to bytes for extraction of message data. I've realized methods used so far are inefficient, especially on a small embedded system.
I've built this project for myself to produce quantitative results of performance comparison between different methods of conversion. I knew which function is going to be the fastest one from the beginning, however real numbers I received actually surprised me.
This is quick summary of results I got from various executions based on 1024 characters to convert:
Function | x64 MSVC | x64 L/GCC | x64 F/CLang | RPI 3 GCC |
---|---|---|---|---|
convert_hex_string_naive_sscanf | 185.7700 us | 50.1654 μs | 504.7270 μs | |
convert_hex_string_naive_strtoul | 33.8518 us | 9.4807 μs | 82.0596 μs | |
convert_hex_string_naive_lookup | 6.0036 us | 2.2786 μs | 22.5882 μs | |
convert_hex_string_calculated | 7.9937 us | 5.0399 μs | 38.5360 μs |
Legend:
- MSVC: Visual Studio 2017
- L/GCC: GCC on Linux
- F/CLang: CLang on FreeBSD
- RPi3: Raspberry Pi 3
One conclusion I clearly see is that Raspberry Pi 3 is only 10 times slower than my i7 notebook 😄
Detailed report in preparation.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
These are minimal versions I personally tested the code with, there is slight possibility it may work with lower versions either:
- gcc >= 6.3.0
- qbs >= 1.7.0
- boost-dev >= 1.62.0
- msvc >= 14.11.25503 || cl >= 19.11.25547
- qbs >= 1.12.1
- boost >= 1.68.0
qbs setup-toolchains --detect
qbs build profile:gcc
If you're using clang instead of gcc, after changing the above profile building should be possible. This hasn't been tested yet.
Build (including tests):
qbs setup-toolchains --detect
qbs build profile:MSVC2017-x86_x64
Basic executions if you wish to run benchmark:
qbs run --products hexstringconvertbenchmark
Some extras if you with to run unit tests:
qbs run --products tests
qbs run --products tests-generator
Special thanks for great tools used in this projects goes to:
Versioning is not yet established.
The content of this project itself is licensed under the Creative Commons Attribution 4.0 International license, and the underlying source code used to prepare results for that content is licensed under Creative Commons Zero 1.0 license.