base64 string to bytearray

Benchmark created by imaya on


Preparation HTML

<script src="https://raw.github.com/imaya/base64.js/master/bin/base64.min.js"></script>
<script>
function native(str) {
  var decoded = atob(str);
  var i, il = decoded.length;
  var array = new Uint8Array(il);

  for (i = 0; i < il; ++i) {
    array[i] = decoded.charCodeAt(i);
  }

  return array;
}
</script>

Setup

var size = 10000;
    var tmp = [];
    var str;
    var i;
            
    for (i = 0; i < size; ++i) {
      tmp[i] = String.fromCharCode(i & 0xff);
    }
            
    str = window.btoa(tmp.join(''));

Test runner

Ready to run.

Testing in
TestOps/sec
js impl
Base64.atobArray(str);
ready
native
native(str);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.