Html程序  |  29行  |  940 B

<html><head><title>Cookie Test</title>
<script>
function cookieTest(){
    var totalW = 0.0;
    var totalR = 0.0;
    var numLoops = 100;
    for(var i=0; i < numLoops; i++){
        var randomNumber=Math.floor(Math.random()*11);
        var time = new Date();
        time.setTime(time.getTime() + 1000);
        var cookieString = "cookie" + randomNumber + "=true; expires=" + time.toGMTString();
        var preW = new Date().getTime();
        document.cookie = cookieString;
        var postW = new Date().getTime();
        if(document.cookie.indexOf(("cookie" + randomNumber)> 0));
        var postR = new Date().getTime();
        totalW += (postW - preW);
        totalR += (postR - postW);
    }
    document.write("<br><br>avg R(millis):" + totalR/numLoops);
    document.write("<br>avg W(millis):" + totalW/numLoops);
}

</script>
</head>
<body onload="javascript:cookieTest();setTimeout(cookieTest(), 1000);">
</body>
</html>