tests/performance/run.js
/**
 * Compare both elements of `allSamples` and display comparative results.
 * Returns false if any of the tested scenario had a significant performance
 * regression.
 * @returns {boolean}
 */
Compare both elements of `allSamples` and display comparative results.
Returns false if any of the tested scenario had a significant performance
regression.
@returns {boolean}
Compare both elements of ` allSamples ` and display comparative results . Returns false if any of the tested scenario had a significant performance regression . @returns { boolean }
function compareSamples() {
  if (allSamples.length !== 2) {
    throw new Error("Not enough result");
  }
  const samplesPerScenario = [getSamplePerScenarios(allSamples[0]),
                              getSamplePerScenarios(allSamples[1])];
  let hasSucceeded = true;
  for (const testName of Object.keys(samplesPerScenario[0])) {
    const sample1 = samplesPerScenario[0][testName];
    const sample2 = samplesPerScenario[1][testName];
    if (sample2 === undefined) {
      console.error("Error: second result misses a scenario:", testName);
      continue;
    }
    const result1 = getResultsForSample(sample1);
    const result2 = getResultsForSample(sample2);
    console.log("For current Player:\n" +
                "===================");
    console.log(`test name: ${testName}\n` +
                `mean: ${result1.mean}\n` +
                `variance: ${result1.variance}\n` +
                `standardDeviation: ${result1.standardDeviation}\n` +
                `standardErrorOfMean: ${result1.standardErrorOfMean}\n` +
                `moe: ${result1.moe}\n`);
    console.log("\nFor previous Player:\n" +
                "===================");
    console.log(`test name: ${testName}\n` +
                `mean: ${result2.mean}\n` +
                `variance: ${result2.variance}\n` +
                `standardDeviation: ${result2.standardDeviation}\n` +
                `standardErrorOfMean: ${result2.standardErrorOfMean}\n` +
                `moe: ${result2.moe}\n`);
    const difference = (result2.mean - result1.mean) / result1.mean;
    console.log(`\nDifference: ${difference * 100}`);
    const uValue = getUValueFromSamples(sample1, sample2);
    const zScore = Math.abs(calculateZScore(uValue,
                                            sample1.length,
                                            sample2.length));
    const isSignificant = zScore > 1.96;
    if (isSignificant) {
      console.log(`The difference is significant (z: ${zScore})`);
      if (difference < 0) {
        hasSucceeded = false;
      }
    } else {
      console.log(`The difference is not significant (z: ${zScore})`);
    }
  }
  return hasSucceeded;
  function calculateZScore(u, len1, len2) {
    return (u - ((len1 * len2) / 2)) /
                Math.sqrt((len1 * len2 * (len1 + len2 + 1)) / 12);
  }
}
function compareSamples ( ) { if ( allSamples . length !== 2 ) { throw new Error ( "Not enough result" ) ; } const samplesPerScenario = [ getSamplePerScenarios ( allSamples [ 0 ] ) , getSamplePerScenarios ( allSamples [ 1 ] ) ] ; let hasSucceeded = true ; for ( const testName of Object . keys ( samplesPerScenario [ 0 ] ) ) { const sample1 = samplesPerScenario [ 0 ] [ testName ] ; const sample2 = samplesPerScenario [ 1 ] [ testName ] ; if ( sample2 === undefined ) { console . error ( "Error: second result misses a scenario:" , testName ) ; continue ; } const result1 = getResultsForSample ( sample1 ) ; const result2 = getResultsForSample ( sample2 ) ; console . log ( "For current Player:\n" + "===================" ) ; console . log ( ` ${ testName } \n ` + ` ${ result1 . mean } \n ` + ` ${ result1 . variance } \n ` + ` ${ result1 . standardDeviation } \n ` + ` ${ result1 . standardErrorOfMean } \n ` + ` ${ result1 . moe } \n ` ) ; console . log ( "\nFor previous Player:\n" + "===================" ) ; console . log ( ` ${ testName } \n ` + ` ${ result2 . mean } \n ` + ` ${ result2 . variance } \n ` + ` ${ result2 . standardDeviation } \n ` + ` ${ result2 . standardErrorOfMean } \n ` + ` ${ result2 . moe } \n ` ) ; const difference = ( result2 . mean - result1 . mean ) / result1 . mean ; console . log ( ` \n ${ difference * 100 } ` ) ; const uValue = getUValueFromSamples ( sample1 , sample2 ) ; const zScore = Math . abs ( calculateZScore ( uValue , sample1 . length , sample2 . length ) ) ; const isSignificant = zScore > 1.96 ; if ( isSignificant ) { console . log ( ` ${ zScore } ` ) ; if ( difference < 0 ) { hasSucceeded = false ; } } else { console . log ( ` ${ zScore } ` ) ; } } return hasSucceeded ; function calculateZScore ( u , len1 , len2 ) { return ( u - ( ( len1 * len2 ) / 2 ) ) / Math . sqrt ( ( len1 * len2 * ( len1 + len2 + 1 ) ) / 12 ) ; } }
Compare both elements of `allSamples` and display comparative results.
Compare both elements of ` allSamples ` and display comparative results .
// eslint-disable-next-line no-console // eslint-disable-next-line no-console // eslint-disable-next-line no-console // eslint-disable-next-line no-console // eslint-disable-next-line no-console // eslint-disable-next-line no-console // eslint-disable-next-line no-console // eslint-disable-next-line no-console