最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2008年11月18日 11:20:54   作者:  
今天看了javascript 高級程序設計 談到了字符串連接的性能問題
書中附帶的測試代碼如下 
復制代碼 代碼如下:

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

相關文章

最新評論

澄迈县| 康平县| 台南市| 花莲市| 汶上县| 安阳市| 文山县| 福海县| 柯坪县| 澜沧| 广平县| 同仁县| 连南| 宜良县| 青岛市| 左权县| 开远市| 鄂温| 柏乡县| 阿鲁科尔沁旗| 闽清县| 建昌县| 鲜城| 淮北市| 开鲁县| 柳林县| 南宁市| 哈巴河县| 桓台县| 云安县| 潍坊市| 茶陵县| 贵定县| 依兰县| 磴口县| 长乐市| 仙游县| 外汇| 浪卡子县| 壤塘县| 西华县|