computeDelta function

BenchmarkResults computeDelta(
  1. BenchmarkResults baseline,
  2. BenchmarkResults test
)

Computes the delta for each matching metric in test and baseline, and returns a new BenchmarkResults object where each BenchmarkScore contains a delta value.

Implementation

BenchmarkResults computeDelta(
  BenchmarkResults baseline,
  BenchmarkResults test,
) {
  final Map<String, List<BenchmarkScore>> delta =
      <String, List<BenchmarkScore>>{};
  for (final String benchmarkName in test.scores.keys) {
    final List<BenchmarkScore> testScores = test.scores[benchmarkName]!;
    final List<BenchmarkScore>? baselineScores = baseline.scores[benchmarkName];
    delta[benchmarkName] = testScores.map<BenchmarkScore>(
      (BenchmarkScore testScore) {
        final BenchmarkScore? baselineScore = baselineScores?.firstWhereOrNull(
            (BenchmarkScore s) => s.metric == testScore.metric);
        return testScore._copyWith(
          delta: baselineScore == null
              ? null
              : (testScore.value - baselineScore.value).toDouble(),
        );
      },
    ).toList();
  }
  return BenchmarkResults(delta);
}