stringBuilder vs stringConcat

JavaScript performance comparison

Test case created

Preparation code

function StringBuilder(str) {
            this.__string__ = new Array(str);
        }
 
        StringBuilder.prototype.append = function (char) {
            this.__string__.push(char);
        }
 
        StringBuilder.prototype.toString = function () {
            return this.__string__.join(' ');
        }
 
       

Preparation code output

function StringBuilder(str) { this.__string__ = new Array(str); } StringBuilder.prototype.append = function (char) { this.__string__.push(char); } StringBuilder.prototype.toString = function () { return this.__string__.join(' '); }

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
stringBuilder
var sb = new StringBuilder();
for(var i = 0;i < 9999;i++){
  sb.append("ga");
}
pending…
stringConcat
var str = "";
for(var i = 0;i < 9999;i++){
  str+="ga";
}
pending…

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

Compare results of other browsers

0 comments

Add a comment