国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-21 01:33:29
字體:
來源:轉載
供稿:網友
書中附帶的測試代碼如下 
復制代碼 代碼如下:

<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中執行的結果如下:
Concatenation with plus: 5 milliseconds
Concatenation with StringBuffer: 10 milliseconds
在IE6中執行結果如下:
Concatenation with plus: 234 milliseconds
Concatenation with StringBuffer: 62 milliseconds
1.兩種方式性能差別很大
2.看來IE6字符串連接處理能力比FF3很差呀
3.IE6和FF3兩種方式結果相反,看來以后寫連接優化還有注意瀏覽器呀
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 饶河县| 九龙县| 庄浪县| 台州市| 龙州县| 深圳市| 梁平县| 通许县| 当涂县| 壤塘县| 康乐县| 太仓市| 夏津县| 杂多县| 芜湖市| 柯坪县| 札达县| 荆州市| 雅安市| 宜宾县| 鹤壁市| 页游| 峨眉山市| 西乌珠穆沁旗| 根河市| 拜城县| 承德县| 遵义市| 江陵县| 岳阳市| 定边县| 寻甸| 清河县| 丰镇市| 陇南市| 绵竹市| 朝阳市| 博白县| 政和县| 泽普县| 屏东市|