String.fromCharCode Test

JavaScript performance comparison

Revision 22 of this test case created by

Preparation code

<script>
  
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var chars = [123, 34, 122, 34, 58, 34, 115, 101, 99, 111, 110, 100, 84, 97, 98, 34, 44, 34, 97, 34, 58, 34, 110, 111, 110, 101, 34, 44, 34, 98, 34, 58, 117, 110, 100, 101, 102, 105, 110, 101, 100, 44, 34, 101, 34, 58, 117, 110, 100, 101, 102, 105, 110, 101, 100, 125];
  // Generate 1M chars
  chars = [];
  for (var i = 0; i < 1 << 20; i++) chars.push(i & 0xFF)
  array = new Uint8Array(chars);
  decoder = new TextDecoder();

};
</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
Using a loop
var s = "";
for (var i = 0, l = chars.length; i < l; i++) {
  s += String.fromCharCode(chars[i]);
}
return s;
pending…
Hybrid
var s = "",
  i = 0,
  l = chars.length;
while (i < l) {
  var end = Math.min(i + 10000, l);
  s += String.fromCharCode.apply(null, chars.slice(i, end));
  i = end;
}
return s;
pending…
Join
return chars.join("");
pending…
TextDecoder
return decoder.decode(array);
pending…
join
var s = [];
for (var i = 0, l = chars.length; i < l; i++) {
  s.push(String.fromCharCode(chars[i]));
}
return s.join('');
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