-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvg_optimizer_benchmark.dart
71 lines (59 loc) · 2.18 KB
/
svg_optimizer_benchmark.dart
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import 'dart:io';
import 'package:args/args.dart';
import 'package:collection/collection.dart';
import 'lib/benchmark.dart';
import 'lib/benchmark_result.dart';
import 'lib/project_size.dart';
import 'lib/supported_platform.dart';
Future<void> main(List<String> arguments) async {
final File yamlFile = File('../example/pubspec.yaml');
final String originalYaml = yamlFile.readAsStringSync();
final ArgParser argParser = buildParser();
final ArgResults results = argParser.parse(arguments);
SupportedPlatform? platform = SupportedPlatform.values
.firstWhereOrNull((element) => results[element.value] == true);
if (platform == null) {
print('Please provide platform argument');
print(argParser.usage);
exit(1);
}
final Benchmark smallProjectBenchmark = Benchmark(
platform: platform,
yamlFile: yamlFile,
originalYaml: originalYaml,
projectSize: ProjectSize.small,
);
final Benchmark mediumProjectBenchmark = Benchmark(
platform: platform,
yamlFile: yamlFile,
originalYaml: originalYaml,
projectSize: ProjectSize.medium,
);
final Benchmark bigProjectBenchmark = Benchmark(
platform: platform,
yamlFile: yamlFile,
originalYaml: originalYaml,
projectSize: ProjectSize.big,
);
try {
print("*** Benchmarking small project... ***\n");
final BenchmarkResult smallResult = await smallProjectBenchmark.execute();
print("\nSmall project benchmark result:\n$smallResult");
print("*** Benchmarking medium project... ***\n");
final BenchmarkResult mediumResult = await mediumProjectBenchmark.execute();
print("\nMedium project benchmark result:\n$mediumResult");
print("*** Benchmarking big project... ***\n");
final BenchmarkResult bigResult = await bigProjectBenchmark.execute();
print("\nBig project benchmark result:\n$bigResult");
} catch (e) {
print(e);
exit(1);
} finally {
// Restore original pubspec.yaml
yamlFile.writeAsStringSync(originalYaml);
}
}
/// Build argument parser with --android and --ios flags
ArgParser buildParser() => ArgParser()
..addFlag(SupportedPlatform.android.value, defaultsTo: false)
..addFlag(SupportedPlatform.ios.value, defaultsTo: false);