用于“JavaScript挑战赛--随机颜色”测试函数性能的页面

 

个人用于测试各位javascript爱好者挑战代码性能的页面如下:



<?xml version="1.0" encoding="UTF-8"?>
 <!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">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>测试函数性能</title>
</head>
<body>
    <div id="debug">
    </div>
    <script type="text/javascript">
        //
        function debug(s){
            document.getElementById("debug").innerHTML += s;
        }
       
        /***
         * name:spiderman
         * qq:1226359491
         * blog:http://blog.csdn.net/FuDesign2008/
         */
        function randomColor_fu(){
            var color = "000000" + Math.round(Math.random() * 0xffffff).toString(16);
            return color.substring(color.length - 6);
        }
       
        /****
         * name:shelly→水
         * qq:49812643
         * blog:
         */
        function randomColor_shelly(){
            return "rgb(" + Math.round(Math.random() * 256) + "," + Math.round(Math.random() * 256) + "," + Math.round(Math.random() * 256) + ")";
        }
        /****
         * name:
         * qq:
         * blog:
         */
        //新增函数
       
        window.onload = function(){
           
            //修改这里以测试不同的函数
            var testFn = randomColor_fu;
            //修改这里以更改函数执行的次数
            var times = 100000;
           
            /*******以下部分不必更改******/
            var index;
            var d1 = (new Date()).getTime();
            for (index = 0; index < times; index++) {
                testFn();
            }
            var d2 = (new Date()).getTime();
            debug(testFn.toString() + "<br/>函数执行" + times + "次: " + (d2 - d1) + " ms");
        }
    </script>
</body>
</html>




有兴趣的朋友可以自己亲自测试一下。

 

如果你有更好的测试方法,麻烦请告诉我,谢谢!

 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值