profiling anonymous javascript functions (chrome)

后端 未结 3 1141
星月不相逢
星月不相逢 2021-01-17 21:57

when performance profiling in chrome anonymous high-use functions are difficult to trouble-shoot when they are listed at the root of the call tree. is there a way to determ

3条回答
  •  悲哀的现实
    2021-01-17 22:11

    You can utilize console.profile([label]), console.profileEnd(), console.time([label]), console.timeEnd([label]).

    For example, execute the below in the JS snippet in console then review the anonynous function execution profile under 'Customize and control DevTools > More tools > JavaScript Profile'.

    console.profile("anonymous function");
    console.time("anonymous function");
    (function() {
      var a = 123;
      function abc() {
        return a
      }
      abc();
    }());
    console.timeEnd("anonymous function");
    console.profileEnd();

    TIP: Storing JS in DevTools Snipets: Select Sources -> Snippets -> right-click -> select New -> place javascript within middle panel -> highlight / select text of javascript within middle panel -> right-click -> select Evaluate in Console -> click right-triangle at right panel or Ctrl+Enter.

提交回复
热议问题