Skip to content

podgorskiy/base64

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

base64

Searching the web for a C/C++ base64 implementation yields many results. The first hit as of 2016-12-10 for "c++ base64" are:

Looking further, we find many more:

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!

Disclaimer

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 implementates 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.

Compared implementations

adp-gmbh (René Nyffenegger)

From http://www.adp-gmbh.ch/cpp/common/base64.html

lib64

From https://sourceforge.net/projects/libb64/

libcurl

From https://curl.haxx.se/libcurl/

Internet Software Consortium

From https://opensource.apple.com/source/basic_cmds/basic_cmds-55/uuencode/base64.c

Arduino-Base64

From https://github.com/adamvr/arduino-base64 from BuLogic's fork (https://github.com/BuLogics/libb64)

LihO

From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c

Manuel Martinez

From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c

DaedalusAlpha

From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c

Elegant Dice

From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c

polfosol

From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c

omnifarious

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.

user152949

From stackoverflow thread at http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c

jounimalinen

From http://web.mit.edu/freebsd/head/contrib/wpa/src/utils/base64.c

test_wikibooks_org_c

From https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64

test_wikibooks_org_cpp

From https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64

apache

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

NibbleAndAHalf

From https://github.com/superwills/NibbleAndAHalf/

Gnome

From https://github.com/GNOME/glib/blob/master/glib/gbase64.c

cppcodec

From https://github.com/tplgy/cppcodec

Results for Encoding (32bit Visual Studio 2015)

The table below shows the number of microseconds for the encoding of different buffer sizes:

Implementation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 68 72 76 80 96 112 128 160 192 224 256
apache 0.107272 0.109874 0.108418 0.112368 0.113487 0.112324 0.114798 0.114436 0.112879 0.198983 0.199052 0.203594 0.2053 0.206689 0.206527 0.207957 0.208973 0.207636 0.209693 0.211857 0.211648 0.210322 0.208795 0.209596 0.209342 0.213156 0.210805 0.213986 0.215526 0.215007 0.216999 0.2212 0.22374 0.224083 0.22553 0.223034 0.224299 0.221733 0.221059 0.224744 0.224981 0.226101 0.224896 0.232075 0.229934 0.232761 0.230755 0.229771 0.233281 0.232544 0.232631 0.240381 0.241165 0.239635 0.241833 0.246243 0.240364 0.242389 0.242162 0.243953 0.250475 0.24564 0.244032 0.243186 0.24911 0.261442 0.260752 0.263289 0.282692 0.291384 0.312266 0.32686 0.354342 0.391914 0.411585
jounimalinen 0.116945 0.120135 0.119827 0.124533 0.126961 0.123922 0.12556 0.126944 0.126419 0.207953 0.205896 0.213323 0.210704 0.209417 0.208586 0.209985 0.211231 0.211595 0.213811 0.214522 0.21624 0.216002 0.218284 0.22159 0.22397 0.224979 0.22036 0.221201 0.225282 0.220686 0.221162 0.225916 0.225883 0.226214 0.224841 0.226839 0.230714 0.230809 0.227632 0.232252 0.238526 0.237746 0.231971 0.231042 0.233279 0.236185 0.235507 0.238087 0.238205 0.243735 0.242036 0.241123 0.243045 0.24066 0.245986 0.247064 0.246648 0.250238 0.249466 0.249547 0.250626 0.253014 0.254703 0.254835 0.256435 0.257322 0.273092 0.275612 0.292918 0.303408 0.322363 0.344941 0.378558 0.419151 0.434379
NibbleAndAHalf 0.116597 0.115518 0.116778 0.122256 0.124338 0.12235 0.124425 0.126561 0.129946 0.215682 0.210449 0.215203 0.217577 0.214509 0.213927 0.217072 0.214548 0.217736 0.221573 0.222749 0.22543 0.229612 0.228851 0.234062 0.234331 0.235352 0.238474 0.236259 0.236497 0.239138 0.238925 0.243109 0.245422 0.239948 0.239373 0.244023 0.246597 0.24283 0.249269 0.246636 0.246226 0.251916 0.249464 0.251701 0.257879 0.256856 0.25581 0.258465 0.266965 0.25881 0.263202 0.259383 0.266259 0.270631 0.270189 0.272725 0.271879 0.271732 0.276799 0.281525 0.276441 0.275447 0.278408 0.276491 0.289264 0.289141 0.298731 0.310245 0.332917 0.35224 0.383732 0.422086 0.462272 0.512932 0.545165
internetsoftwareconsortium 0.115257 0.116053 0.110223 0.121342 0.12098 0.11864 0.124815 0.125146 0.121998 0.219368 0.220235 0.212528 0.217972 0.223357 0.216643 0.229876 0.232764 0.224849 0.230955 1.3659 0.226677 0.233913 0.235012 0.230633 0.23975 0.241266 0.235514 0.242964 0.247031 0.238508 0.249469 0.249177 0.245128 0.255171 0.259358 0.25184 0.260118 0.25817 0.258838 0.273057 0.275565 0.265996 0.274125 0.271166 0.267186 0.271759 0.27407 0.268134 0.282066 0.286918 0.282079 0.287813 0.286647 0.286338 0.295869 0.295616 0.291061 0.301998 0.301387 0.291685 0.300873 0.306202 0.299857 0.304343 0.316577 0.31418 0.330376 0.331954 0.3611 0.382843 0.415684 0.477251 0.522291 0.607917 0.636043
polfosol 0.101834 0.103146 0.104478 0.107201 0.110477 0.109419 0.113974 0.115238 0.114783 0.205934 0.206937 0.205245 0.210234 0.21737 0.214958 0.22149 0.216415 0.217571 0.219057 0.222633 0.219874 0.225758 0.226981 0.229861 0.234125 0.238059 0.234311 0.240252 0.23594 0.23903 0.241235 0.241743 0.240367 0.244349 0.24889 0.254705 0.260901 0.257649 0.25867 0.259463 0.263679 0.260268 0.265119 0.264819 0.271856 0.268498 0.275229 0.273136 0.282904 0.281921 0.272918 0.27631 0.279243 0.284727 0.281549 0.291418 0.288264 0.293761 0.289888 0.295814 0.299102 0.303185 0.303025 0.307904 0.317427 0.323714 0.335027 0.335647 0.366696 0.397239 0.429128 0.494767 0.549747 0.600015 0.652053
wikibooks_org_c 0.111841 0.11237 0.113272 0.118199 0.119268 0.118687 0.124072 0.123435 0.12354 0.213497 0.216511 0.214886 0.222639 0.219644 0.22355 0.229885 0.228831 0.227117 0.23303 0.234915 0.234665 0.242299 0.241615 0.242747 0.246547 0.246222 0.246517 0.248375 0.251941 0.249905 0.254262 0.257238 0.25699 0.26116 0.261516 0.262206 0.267327 0.268851 0.269359 0.273196 0.271578 0.273941 0.283005 0.279922 0.278093 0.285581 0.282363 0.284521 0.288021 0.289664 0.287732 0.293018 0.294559 0.293199 0.302892 0.298181 0.301506 0.304814 0.309547 0.311768 0.310959 0.310851 0.313062 0.31872 0.324646 0.330979 0.344607 0.345094 0.379339 0.4151 0.446048 0.513498 0.570684 0.636349 0.701049
gnome 0.135533 0.133178 0.136323 0.141088 0.142301 0.140361 0.146863 0.149798 0.237919 0.325182 0.323265 0.326513 0.353908 0.34468 0.343271 0.351908 0.347984 0.37542 0.393741 0.358943 0.365761 0.390206 0.380117 0.367369 0.372321 0.383602 0.380668 0.392568 0.386307 0.38475 0.390319 0.388613 0.387994 0.401119 0.391747 0.393943 0.394962 0.394429 0.394188 0.40599 0.404921 0.404345 0.412851 0.409566 0.405893 0.420956 0.413478 0.412663 0.424123 0.425969 0.424524 0.434929 0.492733 0.440431 0.447185 0.445682 0.439731 0.502783 0.506347 0.485935 0.497747 0.460965 0.462629 0.467165 0.470323 0.482962 0.496583 0.520713 0.563158 0.614627 0.644528 0.734544 0.766645 0.838784 0.887723
arduino 0.118509 0.119117 0.122076 0.132471 0.135852 0.137738 0.147221 0.149313 0.150027 0.248766 0.250231 0.249989 0.255977 0.260937 0.259267 0.27324 0.285361 0.287799 0.303425 0.302549 0.293454 0.304654 0.307849 0.306079 0.311677 0.313761 0.319655 0.329641 0.327105 0.332071 0.339899 0.346803 0.354286 0.357898 0.355284 0.358658 0.371691 0.382168 0.374741 0.38412 0.388211 0.392743 0.399104 0.399688 0.399034 0.411836 0.421092 0.411182 0.433069 0.428812 0.434977 0.440116 0.446257 0.445337 0.456127 0.462041 0.461325 0.476475 0.476183 0.475551 0.484894 0.487741 0.487755 0.505399 0.514935 0.53055 0.551778 0.575863 0.645695 0.728413 0.802685 0.960458 1.0898 1.25342 1.38764
elegantdice 0.120279 0.117399 0.114282 0.128019 0.125479 0.124204 0.141976 0.141571 0.139255 0.239164 0.239079 0.235926 0.253402 0.258426 0.254803 0.265197 0.264855 0.26281 0.28161 0.276692 0.274925 0.291926 0.289096 0.287456 0.303269 0.30384 0.310483 0.329711 0.324584 0.322671 0.341857 0.336035 0.335683 0.350838 0.353414 0.347747 0.365522 0.372094 0.362902 0.374118 0.380939 0.370515 0.386478 0.386998 0.382921 0.398647 0.392852 0.403361 0.416809 0.419743 0.417849 0.424565 0.427383 0.431703 0.43796 0.434931 0.435994 0.461213 0.453942 0.455581 0.472892 0.469043 0.471474 0.489294 0.489363 0.511759 0.544592 0.546474 0.636146 0.71266 0.793598 0.916679 1.04726 1.22271 1.39193
daedalusalpha 0.116234 0.116886 0.116678 0.125134 0.125061 0.12768 0.139621 0.137369 0.141683 0.244265 0.246068 0.244841 0.259849 0.258451 0.261099 0.278403 0.27343 0.276961 0.284333 0.283911 0.284893 0.29776 0.298132 0.298584 0.307636 0.307478 0.316421 0.331374 0.327825 0.329681 0.33903 0.338558 0.344509 0.347761 0.341977 0.351996 0.365871 0.3662 0.369573 0.379255 0.381402 0.376258 0.390387 0.39532 0.394264 0.405287 0.402868 0.404522 0.417034 0.418428 0.411923 0.429833 0.425251 0.426483 0.438304 0.439262 0.435069 0.447554 0.450935 0.463644 0.475204 0.469073 0.468742 0.480038 0.488784 0.510492 0.535589 0.536782 0.632651 0.702791 0.800494 0.923296 1.07088 1.21836 1.39385
CppCodec 0.15069 0.158567 0.138497 0.168342 0.166635 0.153346 0.186204 0.188177 0.171308 0.282119 0.282008 0.266554 0.294051 0.300822 0.286171 0.32079 0.325976 0.304998 0.338276 0.340245 0.322298 0.360409 0.359788 0.34343 0.378849 0.376986 0.364181 0.401775 0.402895 0.386545 0.42042 0.425553 0.403445 0.426847 0.437581 0.407885 0.442607 0.45072 0.427876 0.456889 0.466088 0.437493 0.470103 0.481163 0.457022 0.488841 0.495342 0.473969 0.507449 0.509039 0.492679 0.522791 0.534167 0.514197 0.545029 0.545579 0.522751 0.558023 0.557688 0.542154 0.571744 0.591842 0.562313 0.597414 0.61631 0.606543 0.66973 0.679971 0.763969 0.881845 0.964839 1.16263 1.30588 1.55547 1.70925
manuelmartinez 0.108172 0.10647 0.110711 0.126003 0.123382 0.124434 0.139173 0.135681 0.13304 0.241411 0.240099 0.242773 0.255605 0.254181 0.264502 0.27774 0.280288 0.282225 0.291553 0.287108 0.286286 0.403327 0.409142 0.439129 0.426305 0.410181 0.408871 0.422964 0.429584 0.433074 0.443868 0.440035 0.440086 0.55854 0.568374 0.563839 0.580749 0.569478 0.570619 0.603095 0.596884 0.593876 0.599073 0.597557 0.599232 0.628666 0.624621 0.618059 0.619371 0.626572 0.630231 0.751164 0.738812 0.734167 0.750632 0.759031 0.757563 0.776913 0.765035 0.76417 0.786586 0.778931 0.822597 0.803996 0.797341 0.807974 0.986816 0.984886 1.04653 1.12319 1.31857 1.48325 1.73524 1.98801 2.10649
wikibooks_org_cpp 0.14271 0.146374 0.145571 0.177607 0.187325 0.184229 0.217976 0.222482 0.222614 0.438053 0.43716 0.435366 0.474087 0.479739 0.479673 0.512877 0.519873 0.520476 1.78637 1.34597 0.558659 0.592123 0.589943 0.596795 0.627187 0.635859 0.634421 0.667261 0.677495 0.674617 0.707459 0.713615 0.725515 0.759847 0.762032 0.767055 0.798947 0.800616 0.806595 0.830645 0.837096 0.83734 0.86312 0.877364 0.886341 0.91131 0.919791 0.921068 0.954667 0.950945 0.958561 0.992891 0.994779 0.996058 1.02685 1.04625 1.03682 1.07072 1.07567 1.08906 1.11381 1.11478 1.12971 1.15198 1.2061 1.25631 1.30908 1.36422 1.55594 1.78958 2.01713 2.4419 2.89068 3.35203 3.74915
libb64 3.17659 3.12883 3.15834 3.15209 3.14258 3.178 3.16715 3.12729 3.12538 3.23839 3.20614 3.27968 3.19132 3.1893 3.24556 3.28203 3.26046 3.23467 3.29694 3.25188 3.29628 3.39604 3.38097 3.39732 3.39032 3.46107 3.43669 3.4446 3.42091 3.39229 3.40992 3.38423 3.47835 3.46013 3.42236 3.43509 3.43694 3.45813 3.52461 3.467 3.47303 3.45158 3.51038 3.51673 3.48168 3.6036 3.55179 3.60384 3.63859 3.64171 3.62905 3.59909 3.65267 3.66161 3.68359 3.66497 3.60329 3.6336 3.67926 3.75278 3.73815 3.67443 3.63795 3.70231 3.66533 3.91931 3.90857 3.84471 3.91353 4.6746 4.86531 4.03555 4.11412 4.23561 4.52117
adp_gmbh 0.130437 0.135187 0.137281 0.17441 0.173903 0.175788 0.21638 0.214145 0.220453 0.365683 0.365067 0.373757 0.406619 0.412485 0.411453 0.457381 0.456813 0.45488 0.50008 0.496546 0.499269 0.641428 1.14848 0.662961 0.689026 0.686496 0.695506 0.748698 0.763109 0.76246 0.815947 0.818407 0.855545 0.934021 0.927926 0.930044 0.979016 0.980484 0.999209 1.01913 1.01848 1.02604 1.06619 1.08779 1.08015 1.12066 1.12764 1.1288 1.16876 1.18024 1.18304 1.29828 1.31578 1.31994 1.35122 1.36078 1.33491 1.38396 1.39062 1.40174 1.41572 1.42718 1.41426 1.45367 1.50212 1.54737 1.629 1.77318 2.00104 2.24998 2.61392 3.06162 4.33367 4.09796 4.63514
LihO 0.133146 0.134612 0.134648 0.175697 0.17559 0.177427 0.221732 0.218342 0.218391 0.363233 0.367998 0.368506 0.408241 0.413161 0.414054 0.459176 0.46196 0.461679 0.498592 0.510358 0.509126 0.644733 0.642065 0.657747 1.22756 0.699584 0.711025 0.751841 0.755062 0.744157 0.779174 0.780199 0.789521 0.931038 0.935849 0.954129 0.971751 0.985449 0.977745 1.02547 1.01812 1.03311 1.07858 1.07667 1.08211 1.12147 1.12364 1.14075 1.20553 1.20938 1.1946 1.35137 1.32321 1.33653 1.37552 1.38213 1.37107 1.41299 1.42315 1.42967 1.44854 1.44465 1.44855 1.49374 1.53058 1.60591 1.66493 1.82631 2.05441 2.25062 2.67075 3.0798 3.68867 4.11499 5.16166
libcurl 0.368562 0.407932 0.41024 0.629071 0.670976 0.691319 0.918447 0.970725 1.04745 1.29046 1.32689 1.32741 1.56252 1.59809 1.58047 1.85001 1.90847 1.9074 2.1244 2.16088 2.17034 2.38009 2.46765 2.41938 2.64951 2.67721 2.74077 2.95287 3.00535 2.9116 3.16268 3.23702 3.2639 3.49119 3.49484 3.48308 3.72967 3.778 3.81998 4.00746 4.01599 3.98849 4.28185 4.32725 4.32092 4.50267 4.50637 4.56546 4.76766 4.84884 4.81771 5.07249 5.19306 5.34733 5.58479 5.55261 5.56343 5.64327 5.73289 5.79758 6.01446 5.9852 5.90508 6.15877 6.46839 6.83665 7.17291 7.40733 8.77968 10.6584 12.1079 14.8433 17.3067 20.2894 23.7787
user152949 1.52473 1.65298 1.77071 2.09167 2.20589 2.31829 2.64258 2.79838 2.87225 3.25731 3.36725 3.42001 3.83451 3.9549 3.98297 4.34355 4.61771 4.57992 4.91846 5.03753 5.0846 5.39456 5.51518 5.58097 6.12632 6.2005 6.16061 6.51387 6.583 6.92524 7.18224 7.13784 7.25205 7.64068 7.7531 8.00448 8.2758 8.24643 8.33703 8.65576 8.95353 8.98763 9.18868 9.30769 9.39443 9.87169 10.0484 9.89359 10.3836 10.4954 10.5992 10.9085 10.9686 11.0851 11.4787 11.5798 11.6694 11.9691 12.1149 12.1931 12.4919 12.6382 12.7424 13.0695 13.7321 14.2568 15.288 15.8615 18.6555 21.8244 24.4458 30.2765 36.0768 41.6817 47.6459

Performance 1 to 256 bytes_32bit_withcurl

libcurl and user152949 stands out, being slower by a factor of 5x or more than the others. Here's the same graph without them:

Performance 1 to 256 bytes_32bit_withcurl

libb64 seems to have a high fixed cost and a low variable cost - it may be that it will outperform other solutions with larger strings. However, here are results going up to 32K:

Implementation 32768
apache 28.9077
jounimalinen 30.4965
NibbleAndAHalf 46.0619
internetsoftwareconsortium 55.3013
polfosol 57.6273
wikibooks_org_c 61.5319
gnome 70.1095
elegantdice 146.471
daedalusalpha 147.503
arduino 148.96
libb64 152.933
manuelmartinez 158.616
CppCodec 199.157
wikibooks_org_cpp 444.807
adp_gmbh 461.506
LihO 477.591
libcurl 2927.97
user152949 5828.38

Performance 32K

At 32K, it does not outperform the average performing solutions.

Results for Decoding (32bit Visual Studio 2015)

The results for decoding were a bit surprising:

Implementation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 68 72 76 80 96 112 128 160 192 224 256
polfosol_mod 0.118149 0.123965 0.132323 0.138938 0.145724 0.15001 0.148516 0.150063 0.155588 0.159768 0.1595 0.164923 0.173717 0.171869 0.170223 0.215338 0.215379 0.217386 0.227345 0.22246 0.220268 0.22446 0.225513 0.225432 0.229524 0.231721 0.232686 0.233819 0.233246 0.234697 0.235454 0.23709 0.236167 0.239142 0.23941 0.241255 0.243802 0.243888 0.246725 0.248415 0.25319 0.247676 0.24802 0.252393 0.252219 0.251943 0.255852 0.255103 0.260892 0.257177 0.259487 0.26194 0.264223 0.264778 0.265637 0.264138 0.268398 0.270865 0.268431 0.270159 0.271933 0.27514 0.279219 0.278549 0.283793 0.289054 0.295299 0.301789 0.339051 0.350634 0.377717 0.433025 0.468798 0.518242 0.576378
polfosol 0.100702 0.106826 0.10985 0.109027 0.115617 0.113107 0.115669 0.120866 0.114734 0.120469 0.125517 0.118806 0.123652 0.127979 0.123659 0.214104 0.221051 0.216978 0.217385 0.227613 0.218604 0.224076 0.231008 0.225664 0.228497 0.23411 0.232897 0.233949 0.242163 0.234465 0.240245 0.336396 0.236565 0.236179 0.24456 0.238813 0.243833 0.249231 0.243725 0.244191 0.25537 0.248151 0.250483 0.257389 0.251964 0.255336 0.262606 0.256165 0.2634 0.270868 0.260053 0.264833 0.27039 0.268142 0.270558 0.278209 0.271372 0.278462 0.284137 0.281126 0.275952 0.284681 0.279209 0.284619 0.295511 0.291704 0.315345 0.424631 0.348183 0.36591 0.503937 0.443499 0.494216 0.670382 0.593132
apache 0.110918 0.112637 0.1128 0.115436 0.116796 0.117256 0.120226 0.12004 0.121697 0.125924 0.12684 0.129277 0.133936 0.132658 0.138596 0.21958 0.220991 0.224243 0.228728 0.228149 0.232543 0.238972 0.238143 0.238531 0.243478 0.24403 0.248118 0.251792 0.250145 0.252044 0.257865 0.257694 0.26071 0.270123 0.28246 0.280892 0.289329 0.290967 0.293419 0.296373 0.296761 0.304971 0.29982 0.300682 0.305204 0.30808 0.307939 0.311135 0.318607 0.317292 0.318287 0.325781 0.329487 0.324987 0.332062 0.338251 0.332016 0.331896 0.337249 0.335322 0.342252 0.342699 0.346303 0.350187 0.360007 0.367723 0.383254 0.38926 0.425255 0.462645 0.507067 0.570146 0.633098 0.710881 0.777222
wikibooks_org_c 0.111229 0.113674 0.113631 0.118465 0.122923 0.12456 0.127018 0.130975 0.132442 0.135685 0.138639 0.138558 0.1472 0.149395 0.150609 0.244011 0.244376 0.249126 0.253815 0.255917 0.256338 0.265897 0.267103 0.26592 0.272919 0.277666 0.274635 0.281842 0.286899 0.289247 0.288052 0.294788 0.295424 0.300546 0.302239 0.30244 0.307853 0.313565 0.319349 0.319623 0.321207 0.324357 0.343912 0.34685 0.342734 0.352803 0.348426 0.35024 0.356155 0.357952 0.360195 0.365395 0.373828 0.371551 0.37223 0.375427 0.377431 0.383825 0.389348 0.385482 0.392131 0.392381 0.394248 0.407817 0.418862 0.428187 0.44587 0.442508 0.491097 0.533593 0.584836 0.664605 0.750631 0.843889 0.929109
gnome 0.135306 0.136542 0.135691 0.149475 0.152061 0.152209 0.158331 0.160255 0.162773 0.17057 0.168067 0.169957 0.253128 0.253458 0.251367 0.26852 0.269152 0.269162 0.275943 0.274272 0.276532 0.291552 0.289895 0.288 0.306479 0.305429 0.308619 0.322579 0.324028 0.324958 0.326201 0.324285 0.326481 0.337239 0.335942 0.337768 0.346142 0.347202 0.344783 0.355155 0.357403 0.357442 0.370493 0.373733 0.378674 0.380645 0.380386 0.382733 0.390098 0.390588 0.391698 0.401697 0.400481 0.404134 0.411172 0.410863 0.414036 0.424345 0.420461 0.427035 0.435667 0.437693 0.437641 0.447751 0.465231 0.46402 0.489124 0.48997 0.544025 0.606479 0.65449 0.746712 0.857911 0.963168 1.07402
wikibooks_org_cpp 0.137107 0.143881 0.144249 0.157493 0.167668 0.166939 0.272989 0.275596 0.277678 0.286578 0.294554 0.292632 0.306579 0.311492 0.288697 0.368052 0.376547 0.380167 0.391983 0.395297 0.38637 0.403056 0.400953 0.387332 0.451675 0.413564 0.405364 0.43265 0.426948 0.446417 0.442825 0.442383 0.438331 0.452489 0.467213 0.45386 0.461765 0.470416 0.469397 0.478324 0.486763 0.483466 0.489407 0.491247 0.491441 0.502955 0.517575 0.510192 0.520073 0.5276 0.524447 0.531122 0.539423 0.532325 0.554438 0.557554 0.557664 0.567017 0.573378 0.559811 0.579846 0.580522 0.579341 0.583715 0.620598 0.623914 0.659549 0.671767 0.767635 0.823613 0.935837 1.0578 1.20203 1.38228 1.48052
elegantdice 0.110253 0.110717 0.114073 0.126882 0.127934 0.132785 0.143723 0.145128 0.148095 0.161278 0.166388 0.165971 0.170482 0.173628 0.174986 0.2808 0.284577 0.28003 0.296702 0.304132 0.305162 0.322427 0.324715 0.327566 0.342098 0.34322 0.347111 0.354373 0.354776 0.359475 0.362939 0.37055 0.373218 0.381399 0.384892 0.393644 0.400445 0.404646 0.407535 0.416576 0.419383 0.419186 0.430232 0.433547 0.439159 0.447181 0.449758 0.454912 0.476521 0.465976 0.468736 0.480808 0.480806 0.484784 0.49477 0.501236 0.499485 0.507143 0.519608 0.524873 0.534632 0.533557 0.542253 0.538959 0.56585 0.580285 0.606438 0.631546 0.73393 0.818926 0.903711 1.09694 1.29304 1.44603 1.65048
arduino 0.124367 0.129139 0.122853 0.144411 0.144237 0.140172 0.158969 0.158972 0.155904 0.179376 0.178192 0.171242 0.193384 0.192319 0.186305 0.294035 0.294898 0.285843 0.307517 0.309945 0.296224 0.32307 0.327402 0.324803 0.333095 0.341734 0.338541 0.357104 0.361581 0.364713 0.374631 0.375415 0.363743 0.385654 0.387632 0.386409 0.406941 0.403615 0.405239 0.422092 0.422958 0.417488 0.435613 0.445673 0.436503 0.460092 0.457328 0.454343 0.470617 0.468529 0.467974 0.483275 0.494465 0.488319 0.511491 0.508885 0.505187 0.523265 0.522181 0.519024 0.537168 0.544286 0.53834 0.554658 0.580675 0.594415 0.633319 0.642401 0.743742 0.835796 0.92895 1.11668 1.28449 1.46472 1.67344
daedalusalpha 0.118872 0.121192 0.121848 0.135331 0.13691 0.139903 0.153741 0.151942 0.161192 0.261438 0.26775 0.265254 0.268295 0.269995 0.274087 0.396683 0.388986 0.386266 0.399761 0.401692 0.404879 0.416053 0.419976 0.417408 0.431806 0.442834 0.433005 0.454489 0.458858 0.460195 0.475104 0.473412 0.476723 0.491433 0.494367 0.490745 0.509819 0.505507 0.513231 0.527995 0.53051 0.528185 0.542537 0.55311 0.550359 0.553384 0.55582 0.557484 0.57459 0.575148 0.577239 0.59679 0.594004 0.58973 0.60626 0.619204 0.61469 0.632568 0.632142 0.632482 0.64574 0.647673 0.650678 0.661728 0.684214 0.689957 0.729101 0.745124 0.864841 0.951392 1.03651 1.23389 1.41346 1.58532 1.80518
jounimalinen 0.138513 0.142186 0.139679 0.158851 0.162742 0.162503 0.179105 0.183804 0.185565 0.202405 0.20255 0.201732 0.228746 0.231243 0.22742 0.320218 0.319816 0.319282 0.347276 0.341953 0.343176 0.365368 0.362035 0.36467 0.388292 0.390051 0.384603 0.402121 0.400377 0.398604 0.4214 0.42246 0.423776 0.445186 0.441227 0.445614 0.462731 0.465229 0.472534 0.488886 0.491193 0.487079 0.513324 0.513113 0.513193 0.53251 0.531242 0.533583 0.564113 0.562036 0.557499 0.580192 0.579357 0.579187 0.600007 0.601091 0.597094 0.619757 0.626183 0.615954 0.640525 0.641702 0.643635 0.664388 0.685832 0.727263 0.744369 0.772203 0.877957 1.0066 1.14153 1.32958 1.56197 1.78555 2.01
manuelmartinez 0.4096 0.415059 0.418558 0.419317 0.42672 0.429873 0.435647 0.438081 0.438351 0.447444 0.452479 0.456624 0.472904 0.463203 0.467611 0.572164 0.578248 0.572058 0.583636 0.586632 0.589347 0.596787 0.599801 0.599387 0.605057 0.613691 0.615267 0.622288 0.624223 0.628015 0.635372 0.752441 0.73623 0.779458 0.749197 0.76287 0.758522 0.760997 0.761078 0.772036 0.776618 0.77998 0.785183 0.791034 0.79432 0.801088 0.806067 0.907364 0.913254 0.911815 0.917691 0.930092 0.923876 0.927857 0.937557 0.942161 0.944444 0.94667 0.950312 0.957629 0.96135 0.966275 0.967384 0.98425 0.990668 1.11189 1.1212 1.14196 1.23319 1.42418 1.51098 1.79945 1.93607 2.10536 2.42382
CppCodec 0.141055 0.146972 0.140593 0.181367 0.182313 0.181108 0.212921 0.214477 0.214351 0.252656 0.253499 0.249121 0.280565 0.286318 0.284566 0.413248 0.416572 0.414782 0.451 0.451216 0.456696 0.492785 0.50021 0.485557 0.519536 0.518877 0.526112 0.56784 0.560439 0.580831 0.604624 0.604575 0.611048 0.637289 0.657838 0.647043 0.687636 0.680906 0.687179 0.710969 0.737747 0.725958 0.755492 0.755487 0.754503 0.792972 0.804889 0.82052 0.834846 0.838023 0.849878 0.867839 0.873208 0.880266 0.907843 0.921311 0.930049 0.955656 0.951569 0.958065 0.990717 0.985925 1.00017 1.02112 1.09015 1.11958 1.19885 1.24361 1.47434 1.66321 1.87575 2.34964 2.777 3.28984 3.7337
libb64 2.45013 2.38854 2.38942 2.37937 2.38886 2.39571 2.43787 2.43099 2.44393 2.42543 2.4129 2.42727 2.4569 2.44502 2.41129 2.48738 2.50328 2.51153 2.52321 2.55586 2.51755 2.56064 2.53932 2.53629 2.55393 2.59423 2.57251 2.59712 2.59477 2.5966 2.6001 2.60077 2.7165 2.73357 2.72781 2.75023 2.76679 2.75997 2.76055 2.77294 2.77958 2.7895 2.77479 2.78064 2.77567 2.78998 2.78712 2.79883 2.83423 2.82572 2.84713 2.80915 2.80519 2.80176 2.86118 2.83038 2.82786 2.86934 2.86758 2.87922 2.88215 2.8665 2.85726 2.87552 3.00114 3.04033 3.02809 3.05946 3.13153 3.34955 3.43876 3.62757 3.73788 3.81225 3.96402
internetsoftwareconsortium 0.135604 0.161758 0.164959 0.213854 0.221899 0.237674 0.238722 0.278391 0.279141 0.328501 0.357319 0.378045 0.485605 0.492634 0.519268 0.551103 0.591382 0.591928 0.625235 0.669193 0.642841 0.698284 0.67928 0.716567 0.700509 0.751279 0.760212 0.820691 0.812954 0.851921 0.874513 0.854343 0.891177 0.920454 0.970358 0.959435 1.00258 1.01985 1.08718 1.08046 1.02682 1.13023 1.11809 1.16744 1.13436 1.19687 1.18659 1.2619 1.28069 1.26708 1.25916 1.24536 1.30387 1.35724 1.39534 1.36466 1.42567 1.5076 1.42347 1.42681 1.44594 1.49135 1.5436 1.54534 1.65416 1.67699 1.83365 1.9143 2.20027 2.61396 2.93622 3.61259 4.28036 5.08986 5.88355
libcurl 0.135269 0.221731 0.189595 0.278441 0.324443 0.413472 0.294828 0.353842 0.453577 0.409958 0.514761 0.586416 0.540828 0.654843 0.625509 0.840788 0.866102 0.94519 1.03432 1.07686 0.874499 1.02816 1.06249 1.02864 0.930506 1.04686 1.21774 1.40605 1.09711 1.52958 1.48269 1.23179 1.38481 1.54769 1.60625 1.5103 1.68827 1.61818 1.70365 1.70151 1.59113 1.90182 1.87365 1.87054 1.99713 2.00215 1.92933 2.31003 2.22478 2.10063 2.26262 2.13731 2.12481 2.16748 2.53915 2.36186 2.57919 2.48771 2.35429 2.18735 2.50237 2.67865 2.92517 2.63335 3.03366 2.9372 3.29791 3.46938 4.2146 4.65982 5.28627 6.82438 8.04001 9.33265 11.3955
LihO 0.200832 0.219694 0.199774 0.345344 0.34456 0.357022 0.420983 0.438748 0.453982 0.555253 0.576945 0.601498 0.677472 0.711815 0.694353 0.932264 0.941825 0.939055 1.07929 1.09149 1.01839 1.19763 1.18776 1.16446 1.22621 1.27843 1.30797 1.46068 1.36537 1.48128 1.55953 1.55582 1.62049 1.76178 1.75628 1.73165 1.89915 1.85592 1.9164 2.46059 1.9596 2.02557 2.10593 2.11938 2.16339 2.27857 2.21685 2.45059 2.53162 2.46273 2.52609 2.53832 2.54423 2.57708 2.77029 2.72944 2.81704 2.84926 2.79135 2.73187 2.92682 3.02826 3.03176 3.09953 3.30152 3.42744 3.77803 3.88581 4.56597 5.21808 5.91771 7.68035 8.66661 10.4439 12.6315
adp_gmbh 0.209475 0.234301 0.214723 0.36542 0.374458 0.391939 0.466609 0.489803 0.510785 0.610815 0.66594 0.682442 0.771804 0.817743 0.810188 1.05309 1.0621 1.10696 1.23201 1.24374 1.17008 1.35006 1.35821 1.33779 1.36942 1.47349 1.50232 1.67442 1.5531 1.67777 1.82921 1.79899 1.87766 2.00309 2.04931 1.9613 2.17817 2.13072 2.18533 2.26772 2.24121 2.35696 2.47487 2.43142 2.48025 2.59841 2.56752 2.76805 2.91337 2.8522 2.86643 2.96925 2.93879 2.95373 3.12177 3.0836 3.199 3.2406 3.18348 3.23138 3.39761 3.42359 3.52741 4.16719 3.84944 4.0173 4.32387 4.42701 5.2434 6.18663 6.90654 8.9877 10.3403 12.1351 14.3773
user152949 1.56263 1.72881 1.83673 2.16248 2.33526 2.43341 2.7817 2.92215 3.06089 3.36212 3.52552 3.61884 3.94919 4.16032 4.22839 4.68393 4.82273 4.94147 5.26418 5.49898 5.52942 5.82988 6.02082 6.12667 6.43054 6.64832 6.74578 7.08192 7.19858 7.3667 7.66561 7.79815 7.99703 8.28286 8.48972 8.62092 8.91568 9.11106 9.16898 9.50423 9.6593 9.83468 10.1351 10.3154 10.438 10.8461 10.969 10.9927 11.2078 11.4015 11.5855 11.9239 12.2725 12.1929 12.5762 12.7439 12.8227 13.2369 13.4012 13.3287 13.7715 13.9274 13.9946 14.3755 15.1852 15.867 16.7722 17.5232 20.6807 24.1109 27.3195 33.9019 40.1385 46.9977 53.1124

Performance 1 to 256 bytes_32bit_withcurl

Removing the slowest implementations:

Performance 1 to 256 bytes_32bit_withcurl

The fastest implementation is polfosol's snippet from Stack Overflow. What's even more surprising is that by looking just a few minutes at the code, I was able to juice it a little bit more - The implementation is allocating a std::string and then setting the characters using the operator[]. It turns out that operator[] on std::string has some checks for out of bound. Since it is impossible to be out of bound in this context, I changed the code to use the operator[] on a unchecked char pointer and was able to get another 10-15% boost.

Here are the results for a 32K buffer:

Implementation 32768
polfosol_mod 46.5851
polfosol 52.1657
apache 72.8494
wikibooks_org_c 88.3819
gnome 107.384
libb64 120.313
manuelmartinez 159.883
elegantdice 181.565
daedalusalpha 186.847
jounimalinen 230.102
arduino 381.613
wikibooks_org_cpp 405.629
CppCodec 652.674
internetsoftwareconsortium 1029.55
libcurl 1461.21
LihO 2199.47
adp_gmbh 2304.03
user152949 6510.23

Performance 32K

Conclusion

  • For encoding. the Apache and the Internet Software Consortium versions, written over 15 years ago, beats most of the code snippets posted around - which brings us back to how it is important to look for existing implementations before writing new ones. The ISC implementation comes with an unconvenient license from IBM, however, granting you "immunity from suites under its patents, if any, for the use, sale or manufacture of produces to the extent that such products are used for performing Domain Name System";
  • 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;

If you do not need support for line breaks and don't need validation of data integrity, I would recommend using Jouni Malinen or the Apache's implementation for the Encoder, and the modified Polfosol implementation for decoding.

Keep in mind that these results were all obtained using Visual Studio and could differ on another compiler.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 80.7%
  • C 17.0%
  • Makefile 2.3%