色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

javascript 字符串連接的性能問(wèn)題(多瀏覽器)

書(shū)中附帶的測(cè)試代碼如下 
復(fù)制代碼 代碼如下:
<html>
<head>
<title>Example</title>
</head>
<body>
<p><strong>Note:</strong> The latest versions of Firefox seem to have fixed the string concatenation problem. If you are using Firefox 1.0 or later, the string buffer may actually take longer than normal string concatenation.</p>
<script type="text/Javascript">
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 buffer = new StringBuffer();
d1 = new Date();
for (var i=0; i < 10000; i++) {
buffer.append("text");
}
var result = buffer.toString();
d2 = new Date();
document.write("<br />Concatenation with StringBuffer: " + (d2.getTime() - d1.getTime()) + " milliseconds");
</script>

</body>
</html>


在 Firefox/3.0.3中執(zhí)行的結(jié)果如下:
Concatenation with plus: 5 milliseconds
Concatenation with StringBuffer: 10 milliseconds
在IE6中執(zhí)行結(jié)果如下:
Concatenation with plus: 234 milliseconds
Concatenation with StringBuffer: 62 milliseconds
1.兩種方式性能差別很大
2.看來(lái)IE6字符串連接處理能力比FF3很差呀
3.IE6和FF3兩種方式結(jié)果相反,看來(lái)以后寫連接優(yōu)化還有注意瀏覽器呀

JavaScript技術(shù)javascript 字符串連接的性能問(wèn)題(多瀏覽器),轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 都兰县| 密山市| 台中县| 浠水县| 曲麻莱县| 和林格尔县| 武山县| 西吉县| 永和县| 辛集市| 长治市| 镇雄县| 钦州市| 白沙| 三门峡市| 通江县| 同德县| 崇仁县| 钦州市| 藁城市| 鲁山县| 隆德县| 涿州市| 深泽县| 阿图什市| 离岛区| 广汉市| 类乌齐县| 琼中| 托克逊县| 景洪市| 信宜市| 磴口县| 孝义市| 惠来县| 湄潭县| 大石桥市| 茌平县| 万年县| 忻城县| 师宗县|