Searching the web for a C/C++ base64 implementation yields many results.
How does one chose? This project aims at collecting and comparing the different implementations available.
Feel free to improve this test or to submit new implementations!
Keep in mind that some implementations were slightly modified to have a common interface for the test framework. In all cases, line breaks were omitted both for encoding and parsing. Also, although all implementations have been unit-tested, no analysis whatsoever has been made on error handling, so some slower implementation may actually be better at reporting malformed base64 strings for instance.
I do not own any of these implementations - make sure you check their respective license before using them.
From https://github.com/aklomp/base64 A fast C99 implementation with SIMD acceleration
From https://github.com/tobiaslocker/base64
A c++ single-header library implementing the approach of Nick Galbreath's in modp_b64
From https://github.com/matheusgomes28/base64pp A c++ library written for readibility and supported by a blog post https://matgomes.com/base64-encode-decode-cpp/
From http://www.adp-gmbh.ch/cpp/common/base64.html
From https://sourceforge.net/projects/libb64/
From https://curl.haxx.se/libcurl/
From https://opensource.apple.com/source/basic_cmds/basic_cmds-55/uuencode/base64.c
From https://github.com/adamvr/arduino-base64 from BuLogic's fork (https://github.com/BuLogics/libb64)
From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
From stackoverflow thread at http://stackoverflow.com/questions/5288076/doing-base64-encoding-and-decoding-in-openssl-c
** Note that although this implementation is in the results, it does not produce valid results - including extra '=' padding when not necessary.
From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
From http://web.mit.edu/freebsd/head/contrib/wpa/src/utils/base64.c
From https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64
From https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64
Which I think was based on Rob McCool's uuencode's implementation in 1993 https://opensource.apple.com/source/QuickTimeStreamingServer/QuickTimeStreamingServer-452/CommonUtilitiesLib/base64.c
From https://github.com/superwills/NibbleAndAHalf/
From https://github.com/GNOME/glib/blob/master/glib/gbase64.c
From https://github.com/tplgy/cppcodec
- If you want the fastest implementation, go for base64 (Alfred Klomp) noting that the code base is BSD-2
- If you want a simple single-header c++ file with good performance, go for base64 (Tobias Locker)
- Some other implementations are terrible, the slower ones generally allocate memory dynamically as they convert, even though the output size is deterministic and can be preallocated;
- libb64 shows very strange performance results - I get the feeling that they are doing something neat but that I am perhaps not using their code right;
- A lot of implementations are available, everyone claims theirs is better. This test shows that unless you measure, you cannot make any claims about the performance of your code;
Keep in mind that these results were all obtained using Visual Studio and could differ on another compiler.