Chrome为什么不显示有关用户计时API使用情况的任何数据?

时间:2018-07-09 10:33:53

标签: javascript performance google-chrome

Chrome的开发工具没有记录任何由于使用User Timing API而引起的信息。我正在使用Chrome68。我可以看到它可以与其他使用它的网站一起使用,但是我的代码什么也没有显示。没有错误。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        for (let i = 0; i < 50; i++) {
            performance.mark('Test');
            for (let j = 0; j < 500; j++) {
                Math.cbrt(Math.random() * 1000);
                console.log(j);
            }
        }
    </script>
</body>
</html>

enter image description here

1 个答案:

答案 0 :(得分:1)

它认为您需要给它一个开始和结束标签,然后测量,如下所示:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        performance.mark('start');

        for (let i = 0; i < 50; i++) {
            for (let j = 0; j < 500; j++) {
                Math.cbrt(Math.random() * 1000);
                console.log(j);
            }         

        }
            performance.mark('end');
            performance.measure('My Benchmark', 'start', 'end');

    </script>
</body>
</html>