Converting a Uint8Array to a string

JavaScript performance comparison

Revision 2 of this test case created by Robert K

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  bytes = new Uint8Array(100);
  
  for(var i = 0; i < 100; i++) {
    bytes[i] = (i * 73) & 0xFF;
  }
  
  result = "test";

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
array join
var temp = [];

for(var i = 0; i < 100; i++) {
  temp[i] = String.fromCharCode(bytes[i]);
}

result = temp.join("");
pending…
concatenate each character
result = "";
for(var i = 0; i < 100; i++) {
  result = result + String.fromCharCode(bytes[i]);
}
pending…
using apply
result = String.fromCharCode.apply(null, bytes);
pending…

Compare results of other browsers

Revisions

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

0 Comments