diff --git a/tests/e2e/compare/math.js b/tests/e2e/compare/math.ts similarity index 83% rename from tests/e2e/compare/math.js rename to tests/e2e/compare/math.ts index a87c58c4dff3..59a56dd3c842 100644 --- a/tests/e2e/compare/math.js +++ b/tests/e2e/compare/math.ts @@ -7,13 +7,8 @@ * * Based on :: https://github.com/v8/v8/blob/master/test/benchmarks/csuite/compare-baseline.py * - * @param {Number} baselineMean - * @param {Number} baselineStdev - * @param {Number} currentMean - * @param {Number} runs - * @returns {Number} */ -const computeZ = (baselineMean, baselineStdev, currentMean, runs) => { +const computeZ = (baselineMean: number, baselineStdev: number, currentMean: number, runs: number): number => { if (baselineStdev === 0) { return 1000; } @@ -26,10 +21,8 @@ const computeZ = (baselineMean, baselineStdev, currentMean, runs) => { * * Based on :: https://github.com/v8/v8/blob/master/test/benchmarks/csuite/compare-baseline.py * - * @param {Number} z - * @returns {Number} */ -const computeProbability = (z) => { +const computeProbability = (z: number): number => { // p 0.005: two sided < 0.01 if (z > 2.575829) { return 0; diff --git a/tests/e2e/measure/math.js b/tests/e2e/measure/math.ts similarity index 64% rename from tests/e2e/measure/math.js rename to tests/e2e/measure/math.ts index 14f75a7f980e..e1c0cb981a0c 100644 --- a/tests/e2e/measure/math.js +++ b/tests/e2e/measure/math.ts @@ -1,6 +1,13 @@ -import _ from 'underscore'; +type Entries = number[]; -const filterOutliersViaIQR = (data) => { +type Stats = { + mean: number; + stdev: number; + runs: number; + entries: Entries; +}; + +const filterOutliersViaIQR = (data: Entries): Entries => { let q1; let q3; @@ -18,22 +25,17 @@ const filterOutliersViaIQR = (data) => { const maxValue = q3 + iqr * 1.5; const minValue = q1 - iqr * 1.5; - return _.filter(values, (x) => x >= minValue && x <= maxValue); + return values.filter((x) => x >= minValue && x <= maxValue); }; -const mean = (arr) => _.reduce(arr, (a, b) => a + b, 0) / arr.length; +const mean = (arr: Entries): number => arr.reduce((a, b) => a + b, 0) / arr.length; -const std = (arr) => { +const std = (arr: Entries): number => { const avg = mean(arr); - return Math.sqrt( - _.reduce( - _.map(arr, (i) => (i - avg) ** 2), - (a, b) => a + b, - ) / arr.length, - ); + return Math.sqrt(arr.map((i) => (i - avg) ** 2).reduce((a, b) => a + b) / arr.length); }; -const getStats = (entries) => { +const getStats = (entries: Entries): Stats => { const cleanedEntries = filterOutliersViaIQR(entries); const meanDuration = mean(cleanedEntries); const stdevDuration = std(cleanedEntries); @@ -46,5 +48,4 @@ const getStats = (entries) => { }; }; -// eslint-disable-next-line import/prefer-default-export export default getStats;