Base64 Encoding Performance: JDK vs Apache Commons

Dmitry Komanov
2 min readSep 24, 2022
A runner with T-Shirt “j.u.Base64” crosses the finish line
Cover image by mohamed_hassan (with minor change) from Pixabay

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.

Benchmarks

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

A bar chart for all JDKs
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.

A line chart for all data lenghts
Encoding/Decoding, all lengths, openjdk-17

Conclusion

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.

--

--

Dmitry Komanov

Software developer, moved to Israel from Russia, trying to be aware of things.