日期:2014-05-16 浏览次数:20417 次
<script type=text/javascript >
var i = 100000, arr = [];
while (i --) {
arr.push(i + 1);
}
arr.sort(function(){return Math.random() > 0.6});
// -----------------------------------------------
var t = new Date();
var i = arr.length, j = 100001, bit = [], jsout = [];
while (i --) {
bit[arr[i] >> 5] |= (1 << (arr[i] & 0x1f));
}
while (j --) {
if (bit[j >> 5] & (1 << (j & 0x1f))) {
jsout[jsout.length] = j;
}
}
t = new Date() - t;
// ------------------------------------------------
alert("排序时间为:" + t + "毫秒\n");
alert("排序结果为:" + jsout.join("\n"));
</script>
<script type=text/javascript >
var i = 100000, arr = [];
while (i --) {
arr.push(i + 1);
}
m = arr.splice(Math.random() * arr.length, 1);
n = arr.splice(Math.random() * arr.length, 1);
o = arr.splice(Math.random() * arr.length, 1);
p = arr.splice(Math.random() * arr.length, 1);
q = arr.splice(Math.random() * arr.length, 1);
arr.sort(function(){return Math.random() > 0.6});
// -----------------------------------------------
var t = new Date();
var i = arr.length, j = 100001, k = 0, bit = [], jsout = [j], check = [];
while (i --) {
bit[arr[i] >> 5] |= (1 << (arr[i] & 0x1f));
}
while (j --) {
if (bit[j >> 5] & (1 << (j & 0x1f))) {
jsout[1] = jsout[0], jsout[0] = j;
k = jsout[1] - jsout[0];
if (k == 2) {
check = check.concat([jsout[0] + 1]);
}
if (k == 3) {
check = check.concat([jsout[0] + 1, jsout[0] + 2]);
}
if (k == 4) {
check = check.concat([jsout[0] + 1, jsout[0] + 2, jsout[0] + 3]);
}
if (k == 5) {