src/lib/runner.js
// of a single test is changed.
of a single test is changed.
of a single test is changed .
async function run(onChange) {
    function notify() {
      onChange(tests);
    }
    let score = {
      load: 0,
      rest: 0,
    };
    for (let testId in tests) {
      let test = tests[testId];
      const { opts, benchmarkFn } = test;
      const totalRuns = opts.times || 1;
      test.state = "running";
      notify();
      let measurements = {};
      for (let i = 0; i < totalRuns; i++) {
        clearAllTimings();
        const results = await benchmarkFn();
        results.forEach((result) => {
          const { name } = result;
          if (!measurements[name]) {
            measurements[name] = [];
          }
          measurements[name].push(
            opts.bucket === "load"
              ? {
                  name: result.name,
                  duration: cleanupMeasurement(result.duration),
                }
              : { name: result.name, duration: result.duration }
          );
        });
        test.progress = Math.round((100 * (i + 1)) / totalRuns);
        notify();
      }
      const medians = Object.keys(measurements).map((name) => ({
        name,
        median: median(measurements[name].map((m) => m.duration)),
      }));
      const totalTime = Math.round(
        medians.reduce((sum, { median }) => sum + median, 0)
      );
      if (score.hasOwnProperty(opts.bucket)) {
        if (opts.bucket !== "load" || score.load === 0) {
          score[opts.bucket] += totalTime;
        }
      }
      test.totalTime = totalTime;
      test.medians = medians;
      test.state = "complete";
      notify();
    }
    return score;
  }
async function run ( onChange ) { function notify ( ) { onChange ( tests ) ; } let score = { load : 0 , rest : 0 , } ; for ( let testId in tests ) { let test = tests [ testId ] ; const { opts , benchmarkFn } = test ; const totalRuns = opts . times || 1 ; test . state = "running" ; notify ( ) ; let measurements = { } ; for ( let i = 0 ; i < totalRuns ; i ++ ) { clearAllTimings ( ) ; const results = await benchmarkFn ( ) ; results . forEach ( ( result ) => { const { name } = result ; if ( ! measurements [ name ] ) { measurements [ name ] = [ ] ; } measurements [ name ] . push ( opts . bucket === "load" ? { name : result . name , duration : cleanupMeasurement ( result . duration ) , } : { name : result . name , duration : result . duration } ) ; } ) ; test . progress = Math . round ( ( 100 * ( i + 1 ) ) / totalRuns ) ; notify ( ) ; } const medians = Object . keys ( measurements ) . map ( ( name ) => ( { name , median : median ( measurements [ name ] . map ( ( m ) => m . duration ) ) , } ) ) ; const totalTime = Math . round ( medians . reduce ( ( sum , { median } ) => sum + median , 0 ) ) ; if ( score . hasOwnProperty ( opts . bucket ) ) { if ( opts . bucket !== "load" || score . load === 0 ) { score [ opts . bucket ] += totalTime ; } } test . totalTime = totalTime ; test . medians = medians ; test . state = "complete" ; notify ( ) ; } return score ; }
of a single test is changed.
of a single test is changed .
// Mark the current test as running and re-render. // benchmarkFn returns an array of performance measurement objects. In // a first step, we filter those results. // remove time to load chunks and the pdf from `load` // Update the progress indicator and re-render. // Collect all relevant timings. // Add the total time of the test to the final score. // Update the state and re-render