阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js perf_hooks performance.timerify

      Node.js perf_hooks performance.timerify(fn)

      新增于: v8.5.0

      • fn < Function>

      Wraps a function within a new function that measures the running time of the wrapped function. A PerformanceObserver must be subscribed to the ‘function’ event type in order for the timing details to be accessed.

      const {
        performance,
        PerformanceObserver
      } = require('perf_hooks');
      
      function someFunction() {
        console.log('hello world');
      }
      
      const wrapped = performance.timerify(someFunction);
      
      const obs = new PerformanceObserver((list) => {
        console.log(list.getEntries()[0].duration);
        obs.disconnect();
      });
      obs.observe({ entryTypes: ['function'] });
      
      // A performance timeline entry will be created
      wrapped();
      

      更多内容请参考:Node.js perf_hooks 性能钩子,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录