- function StringBuffer() {
- this._strings = new Array;
- }
- StringBuffer.prototype.append = function (str) {
- this._strings.push(str);
- };
- StringBuffer.prototype.toString = function () {
- return this._strings.join(“”);
- };
- var d1 = new Date();
- var str = “”;
- for (var i=0; i < 10000; i++) {
- str += “text”;
- }
- var d2 = new Date();
- document.write(“Concatenation with plus: “ + (d2.getTime() - d1.getTime()) + “
- milliseconds”);
- var oBuffer = new StringBuffer();
- d1 = new Date();
- for (var i=0; i < 10000; i++) {
- oBuffer.append(“text”);
- }
- var sResult = buffer.toString();
- d2 = new Date();
- document.write(“<br />Concatenation with StringBuffer: “ + (d2.getTime() -
- d1.getTime()) + “ milliseconds”);