• 在浏览器中怎么测试一个算法耗时?


    用console.time()和console.timeEnd()即可

    Console.time()

    Starts a timer you can use to track how long an operation takes. You give each timer a unique name, and may have up to 10,000 timers running on a given page. When you call console.timeEnd() with the same name, the browser will output the time, in milliseconds, that elapsed since the timer was started.

    See Timers in the console documentation for details and examples.

    我们可以开启一个定时器来测量程序的耗时,你必须给定时器指定一个名字,每个web页面最多有10000个定时器可以设置。当你调用console.timeEnd()来终止定时器的时候,浏览器会以ms输出时间,这个时间就是程序的耗时。

    举个栗子。

    console.time(1);

    var a=document.getElementById('testdiv');

    console.timeEnd(1);

    参考资料:

    https://developer.mozilla.org/en-US/docs/Web/API/Console/time

  • 相关阅读:
    MySQl的绑定变量特性
    数数 / DP
    MODE
    题单
    对拍
    二、图论
    sync_with_stdio(false)的副作用
    九大编程语言
    Codeforces Round #575 (Div. 3) A B C
    Educational Codeforces Round 69 (Rated for Div. 2) A B C D
  • 原文地址:https://www.cnblogs.com/yfish/p/7081073.html
Copyright © 2020-2023  润新知