String concat replacer

JavaScript performance comparison

Revision 6 of this test case created by

Preparation code

<script>
  var str0 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str1 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefga";

  var str2 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str3 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str4 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str5 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str6 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str7 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str8 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

  var str9 = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg";

String.prototype.fastConcat1 = function() {
  var stringList = arguments;
  var res = "";
  for (var i in stringList) {
    if (stringList[i]) {
      res += stringList[i];
    }
  }
  return res;
};

String.prototype.fastConcat2 = function() {
  var res = '';
  for (let s of arguments) {
    res += s;
  }
  return res;
};

String.prototype.fastConcat3 = function() {
  var res = '';
  for (var s of arguments) {
    res += s;
  }
  return res;
};

String.prototype.fastConcat4 = function() {
  var args = Array.prototype.slice.call(arguments);
  var res = '';
  args.forEach(function(s) {
    res += s;
  });
  return res;
};

String.prototype.es6concat = function(...args) {
  var res = '';
  args.forEach(function(s) {
    res += s;
  });
  return res;
};

String.prototype.es6concat2 = function(...args) {
  return args.reduce((p, c) => p + c);
};

String.prototype.es6concat3 = function(...args) {
  var res = '';
  for(var i = 0; i < args.length; i++) {
    res += args[i];
  };
  return res;
};
</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
ES6 concat 3
var result10 = str0.es6concat3(str1, str2, str3, str4, str5, str6, str7, str8, str9);
pending…

Revisions

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

0 Comments