title: How to measure the execution time of a promise?
body: <p>I'm trying to write a function that measures the execution time of another function:</p>
  
  <pre><code>export class Profiler {
      public measureSyncFunc(fn: () =&gt; any): Promise&lt;number&gt; {
          return new Promise&lt;number&gt;((resolve, reject) =&gt; {
              let elapsed = 0;
  
              let intervalId = window.setInterval(() =&gt; {
                  elapsed += 1; // this is never called
              }, 1);
  
              this.execFunc(fn)
                  .then((result: any) =&gt; {
                      window.clearInterval(intervalId);
                      resolve(elapsed);
                  });
          });
      }
  
      private execFunc(fn: () =&gt; any): Promise&lt;any&gt; {
          return new Promise&lt;any&gt;((resolve, reject) =&gt; {
              resolve(fn());
          });
      }
  }
  </code></pre>
  
  <p>Then I use it like that:</p>
  
  <pre><code>let array = generateRandomArray(100000);
  
  instance.measureSyncFunc(bubbleSort(array))
      .then((elapsed: number) =&gt; {
          console.log(`end session: ${elapsed} seconds`);
          resolve();
      });
  </code></pre>
  
  <p>The bubbleSort function is synchronous and it takes several seconds to complete.
  See code <a href="https://gist.github.com/VivienAdnot/16c475f619ee3cf4bed63b15cc254f29" rel="noreferrer">here</a>: </p>
  
  <p>The result in the console is "end session: 0 seconds" because the interval callback is never called.</p>
  
  <p>Do you know how I can make it called ?
  Thank you very much guys !</p>