UPD. Charts updated with better input data.

Recently I stumbled upon some old code that used Base64 from Apache Commons. So I decided to compare its performance to java.util.Base64.

It’s not a new topic whatsoever (links at the end), so let’s just jump to benchmark results.


Performance for encoding 10K characters for different JDKs. java.util.Base64 is a clear winner performing almost 10x faster.

Encoding/Decoding, all JDKs

Performance for different data sizes (from 1 byte to 10K bytes) for openjdk-17. As you could see in the previous chart, openjdk-8 performs worse, but still java.util.Base64 is clearly better in all cases.

Encoding/Decoding, all lengths, openjdk-17


It’s clearly a time to replace old usages of Apache Commons for base64 encoding. Unless you are on JDK7 or lower, then it’s time to upgrade this part first ;-) (as java.util.Base64 was introduced in JDK8)

Read More

Play with charts here. Source code is on GitHub. Originally posted on Medium. Cover image by mohamed_hassan from Pixabay.