comparing stringbuilders

JavaScript performance comparison

Test case created

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
radoslavzi
        function StringBuilder() {
            this.__string__ = [];
        }
 
        StringBuilder.prototype.append = function (char) {
            this.__string__.push(char);
        }
 
        StringBuilder.prototype.toString = function () {
            return this.__string__.join(' ');
        }
 
        var str = new StringBuilder();
        for (var i = 0; i < 1000000; i++) {
            str.append('hhhh');
        }
        var d2 = new Date();

var t1 = new Date();
        var str = '';
        for (var i = 0; i < 100000; i++) {
            str += 'hhh';
        }
        var t2 = new Date();
pending…
nobos SB
function buildStringBuilder() {
    return {
        string: [],
        len: 0,
        append: function (str) {
            this.string[this.len++] = str;
            return this;
        },
        toString: function () {
            return this.string.join("");
        },
        Reverse: function () {
            var reversed = "";
            for (var i = this.string.length - 1; i >= 0; i--) {
                for (var j = this.string[i].length - 1; j >= 0; j--) {
                    reversed += this.string[i].charAt(j);
                }
            }
            return reversed;
        },
        Clear: function () {
            this.string = [];
            this.len = 0;
        }
    };
}

var str = new buildStringBuilder();
        for (var i = 0; i < 1000000; i++) {
            str.append('hhhh');
        }
        var d2 = new Date();

var t1 = new Date();
        var str = '';
        for (var i = 0; i < 100000; i++) {
            str += 'hhh';
        }
        var t2 = new Date();
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