String.fromCharCode Test

JavaScript performance comparison

Revision 11 of this test case created by 4esn0k

Preparation code

<script>
  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];

var textDecoder = self.TextDecoder ? new TextDecoder("utf-16le") : null;
var uint8array = new Uint8Array(chars.length * 2);

</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 i = -1;
var l = chars.length;
var s = "";
while (++i < l) {
  s += String.fromCharCode(chars[i]);
}
pending…
Using apply
var i = -1;
var l = chars.length;
while (++i < l) {
  chars[i] = chars[i];
}
var s = String.fromCharCode.apply(null, chars);
pending…
TextDecoder
var i = -1;
var l = chars.length;
var k = -1;
while (++i < l) {
  uint8array[++k] = chars[i] & 0xff;
  uint8array[++k] = chars[i] >>> 8;
}
var s = textDecoder.decode(uint8array);
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