迷域, 不同脚本引擎, 相同的写法, 效率怎么送别这么大呀....
最近在做一些效率测试,,,,
得出的结论是 IE 的脚本引擎最稳定, Opera 的最不稳定, Firefox 的处于中间....
运行下面的代码, 在 以上提到的浏览器上运行...
真有点迷域呀...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<!-- DW6 -->
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 " />
<title> shawl.qiu template </title>
<script type= "text/javascript ">
// <![CDATA[
var iUnder = 1, iOver = 200;
var StartTime = new Date();
fRndNoRept(iUnder, iOver)
var EndTime = new Date();
defaultStatus =
"fRndNoRept( "+iUnder+ ", "+iOver+ "): "+(EndTime-StartTime);
;
var StartTime = new Date();
fRandomNoRepeat(iUnder, iOver)
var EndTime = new Date();
defaultStatus +=
" fRandomNoRepeat( "+iUnder+ ", "+iOver+ "): "+(EndTime-StartTime);
;
fRandomNoRepeat(iUnder, iOver);
function fRandomNoRepeat(iUnder, iOver)
{
if(!iUnder) iUnder = 100;
if(!iOver)
{
iOver = iUnder;
iUnder = 1;
}
iOver -= 0;
iUnder -= 0;
var ar = [];
var iArLenCount = 0;
var arLen = iOver-iUnder+1;
var iUnderCount = iUnder;
while(iUnderCount <=iOver)
{
ar[iArLenCount++] = iUnderCount++;
}
var str = ar.join();
var iMax = iOver*100;
var iCount = 0;
var arFinal = [];
var iarFinalCount = 0;
var iTemp = null;
while(/[0-9]/.test(str))
{
var Re = new RegExp( "(\\b "+fRandomBy(iUnder,iOver)+ "\\b) ", " ");
//alert(iTemp)
str =
str.replace
(
Re
,
function($1, $2)
{
ar[$2] = $2;
}
);
}
return ar;
function fRandomBy(under, over)
{// shawl.qiu script
switch(arguments.length)
{
case 1: return parseInt(Math.random()*under+1);
case 2: return parseInt(Math.random()*(over-under+1) + under);
default: return 0;
} // end switch
} // end function fRandomBy
} // end function fRandomNoRepeat
function fRndNoRept(iUnder, iOver)
{// shawl.qiu script
if(!iUnder&&iUnder===false) var iUnder=100;
if(!iOver){
var iOver=iUnder;
iUnder=1;
}
iUnder -=0; iOver -= 0;
var ar=[];
var iArLen=temp=0;
var bln;
var iMax = iOver-iUnder+1;
while(iArLen <iMax)
{
bln=true;
temp=fRandomBy(iUnder, iOver);
var iLenCount = 0;
while(iLenCount++ <iArLen)
{
if(ar[iLenCount-1]==temp)
{
bln=false;
break;
}
} // end while 1
if(bln)ar[iArLen++]=temp;
}// end while
return ar;
function fRandomBy(under, over)
{// shawl.qiu script
switch(arguments.length)
{
case 1: return parseInt(Math.random()*under+1);
case 2: return parseInt(Math.random()*(over-under+1) + under);
default: return 0;
} // end switch
} // end function fRandomBy
} // end function fRndNoRept
//]]>
</script>
</head>
<body>
</body>
</html>
[解决办法]
关注
[解决办法]
studying。。。。。。。。。
[解决办法]
一早就看到搞这么一大堆代码,会得脑淤血的,哈
MS 财大气粗,当然有钱请高人,做出来的东西怎么会差?!
[解决办法]
晕倒,哈,上来就看到个散分贴,高兴ing..
[解决办法]
问题是你用了数组的join方法
这个以前有一些帖子说过这个
[解决办法]
jf
[解决办法]
20.1 循环体内/外定义变量(没多大差别)
20.2 循环体嵌套大小放置问题(IE里没什么差别,FF有区别)
20.3 for vs while (没有差别)
20.4 遍历数组使用 while or for in or for next(for...in最慢,while与for没差别)
20.5 遍历数组时, 是否在循环体内定义当前索变量(你这种测试设计就有问题)
for(var i=0, n=a.length; i <n; i++){}
[解决办法]
恩,看高手过招就是爽!
继续学习!
JF,哈
[解决办法]
确实,IE的正则处理是所有浏览器里最牛的!