forked from flutter/devtools
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.dart
More file actions
53 lines (47 loc) · 1.55 KB
/
utils.dart
File metadata and controls
53 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2023 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
import 'dart:io';
import 'package:web_benchmarks/analysis.dart';
File? checkFileExists(String path) {
final testFile = File.fromUri(Uri.parse(path));
if (!testFile.existsSync()) {
stdout.writeln('Could not locate file at $path.');
return null;
}
return testFile;
}
String convertToCsvLine(List<String> content) {
return content.map((e) => '"$e"').join(',');
}
extension BenchmarkResultsExtension on BenchmarkResults {
List<List<String>> toCsvLines() {
final lines = <List<String>>[];
for (final benchmarkName in scores.keys) {
final scoresForBenchmark = scores[benchmarkName] ?? <BenchmarkScore>[];
for (var i = 0; i < scoresForBenchmark.length; i++) {
final score = scoresForBenchmark[i];
lines.add([
// Include the benchmark name for the line containing the first
// score metric, and a blank cell otherwise.
i == 0 ? benchmarkName : '',
...score.toCsvLine(),
]);
}
}
return lines;
}
}
extension BenchmarkScoreExtension on BenchmarkScore {
List<String> toCsvLine() {
return [
metric, // Metric name
value.toString(), // Value
delta?.toString() ?? '', // Delta value
// value - delta represents the baseline score.
delta != null
? (delta! / (value - delta!)).toString()
: '', // Delta % value
];
}
}