迷域, 不同脚本引擎, 相同的写法, 效率怎么送别这么大呀....
最近在做一些效率测试,,,,
得出的结论是 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)
{// &nb