Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is faster, hex encoding or base64 encoding? [closed]

I want to send or store a huge binary file, which must be encoded as text.

Which would be the faster encoding method between hex encoding and base64 encoding?

The data is around 40 MB or more, which is why the performance matters.

like image 229
Art and Artistic artandartisti Avatar asked Nov 15 '14 06:11

Art and Artistic artandartisti


People also ask

Is Base64 more efficient than hex?

The difference between Base64 and hex is really just how bytes are represented. Hex is another way of saying "Base16". Hex will take two characters for each byte - Base64 takes 4 characters for every 3 bytes, so it's more efficient than hex.

Is Base64 encoding fast?

Base64 is commonly used in cryptography to exchange keys. A form of base64 is also used to pass arbitrary data as part of a URI. Thankfully, encoding and decoding base64 is fast.

Is Base64 shorter than hex?

Base64 and Hex are just two different representations of the same value. Base64 uses more characters and therefore the representation is shorter.

Do Base64 images load faster?

Although Base64 is a relatively efficient way of encoding binary data it will, on average still increase the file size for more than 25%. This not only increases your bandwidth bill, but also increases the download time.


1 Answers

The time spent on the encoding itself isn't really the issue. Base64 is more complex, but the encoding will still not be a large overhead. The real issue is the time spent on transmitting the data over the network, which depends on the encoded size of the data.

  • Base64 expands the size of data compared to its binary form by one third. So your 40 MB file will be about 53 MB.

  • Hex encoding doubles the size of the data, so your 40 MB file will be 80 MB.

In short, Base64 wins.

like image 117
Boann Avatar answered Sep 29 '22 19:09

Boann