String.fromCharCode Test (v4)

Revision 4 of this benchmark created on


Description

Compare the performance of using String.fromCharCode.apply as opposed to using a loop.

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
Concatenate String
var s = "";
for(var i=0,l=chars.length; i<l; i++)
    s += String.fromCharCode(chars[i]);
ready
Join Array
var a = []
for(var i=0,l=chars.length; i<l; i++){
    a.push( String.fromCharCode(chars[i]) )
}
var s = a.join('')
ready
fromCharCode Apply with window
var s = String.fromCharCode.apply(window, chars);
ready
fromCharCode Apply
var s = String.fromCharCode.apply(null, chars);
ready
fromCharCode Call
var s = String.fromCharCode.call(null, chars);
ready
one single call
String.fromCharCode(97)
ready

Revisions

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