阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js perf_hooks 性能钩子

      Node.js perf_hooks 性能钩子

      The Performance Timing API provides an implementation of the W3C Performance Timeline specification. The purpose of the API is to support collection of high resolution performance metrics. This is the same Performance API as implemented in modern Web browsers.

      const { PerformanceObserver, performance } = require('perf_hooks');
      
      const obs = new PerformanceObserver((items) => {
        console.log(items.getEntries()[0].duration);
        performance.clearMarks();
      });
      obs.observe({ entryTypes: ['measure'] });
      
      performance.mark('A');
      doSomeLongRunningProcess(() => {
        performance.mark('B');
        performance.measure('A to B', 'A', 'B');
      });
      
      目录
      本文目录
      目录