Project Description

If you wonder why another one, then focus on the title. What you get is significant performance in encoding and light speed in decoding.

History

I was using a great piece of code written by Fred Palmer titled Screaming Fast Cross-browser Compatible Javascript Base64 Encoding/Decoding, available at https://code.google.com/p/javascriptbase64/. This is the script that inspired me for an even faster version.

Performance

Performance testing with accuracy in JavaScript is not an easy task and there is a lot of talking about the "techniques" and the "environments". I chose JSLitmus, a lightweight tool for creating ad-hoc JavaScript benchmark tests written by Robert Kieffer available at http://broofa.com/Tools/JSLitmus/JSLitmus.js Having all in hand I combined my script with Fred’s and Robert’s scripts into a single html file (https://jsbase64.codeplex.com/downloads/get/666485).

Running performance and comparison tests for encoding and decoding ASCII and UTF-8 input on my laptop using different browsers, I got the following results (B64 is my script and Base64 is Fred’s script):

Chrome
chart-chrome.png

Safari
chart-safari.png

Firefox
chart-firefox.png

Opera
chart-opera.png

IE10
chart-ie10.png

IE9 (using IETester v0.4.12 http://www.my-debugbar.com/wiki/IETester/HomePage)
chart-ie9.png

Conclusion

What is obvious (and known) is that JavaScript engines in browsers are not the same thing performance-wise. Beyond that, my goal for a really fast encoder/decoded is achieved. For chrome (my favorite browser) the performance gains are 120% for ASCII input encoding and 342% for decoding, and 137% for UTF-8 input encoding and 460% for decoding. For IE-10 the gains are 138%, 148%, 214% and 131% respectively. While these figures were generated within an "ideal environment", I suggest you to run the tests on your machines. What you should have in mind is that these tests are affected by various factors such as the available memory, the system load, the browser's tabs that are open and their contents (javascript timers, flash…) ...

I assume that there is space for micro-optimizations, but I leave this task for you. Your comments and ratings are welcomed. Thank you for your time.

Last edited Apr 21, 2013 at 2:11 PM by drdigit, version 3