Beispiel #1
0
 /**
  * Exercises change detection in a loop and then prints the average amount of
  * time in milliseconds how long a single round of change detection takes for
  * the current state of the UI. It runs a minimum of 5 rounds for a minimum
  * of 500 milliseconds.
  *
  * Optionally, a user may pass a `config` parameter containing a map of
  * options. Supported options are:
  *
  * `record` (boolean) - causes the profiler to record a CPU profile while
  * it exercises the change detector. Example:
  *
  * ```
  * ng.profiler.timeChangeDetection({record: true})
  * ```
  */
 timeChangeDetection(config) {
     var record = isPresent(config) && config['record'];
     var profileName = 'Change Detection';
     // Profiler is not available in Android browsers, nor in IE 9 without dev tools opened
     var isProfilerAvailable = isPresent(window.console.profile);
     if (record && isProfilerAvailable) {
         window.console.profile(profileName);
     }
     var start = DOM.performanceNow();
     var numTicks = 0;
     while (numTicks < 5 || (DOM.performanceNow() - start) < 500) {
         this.appRef.tick();
         numTicks++;
     }
     var end = DOM.performanceNow();
     if (record && isProfilerAvailable) {
         // need to cast to <any> because type checker thinks there's no argument
         // while in fact there is:
         //
         // https://developer.mozilla.org/en-US/docs/Web/API/Console/profileEnd
         window.console.profileEnd(profileName);
     }
     var msPerTick = (end - start) / numTicks;
     window.console.log(`ran ${numTicks} change detection cycles`);
     window.console.log(`${NumberWrapper.toFixed(msPerTick, 2)} ms per check`);
     return new ChangeDetectionPerfRecord(msPerTick, numTicks);
 }
Beispiel #2
0
    return function() {
      window.console.profile(name + ' w GC');
      var duration = 0;
      var count = 0;
      while(count++ < 150) {
        gc();
        var start = window.performance.now();
        create();
        duration += window.performance.now() - start;
        destroy();
      }
      window.console.profileEnd(name + ' w GC');
      window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);

      window.console.profile(name + ' w/o GC');
      duration = 0;
      count = 0;
      while(count++ < 150) {
        var start = window.performance.now();
        create();
        duration += window.performance.now() - start;
        destroy();
      }
      window.console.profileEnd(name + ' w/o GC');
      window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
    };
export function windowProfileEnd(name) {
    window.console.profileEnd(name);
}
export function microBenchmark(name, iterationCount, callback) {
    var durationName = `${name}/${iterationCount}`;
    window.console.time(durationName);
    callback();
    window.console.timeEnd(durationName);
}