Skip to content

Commit 32e3816

Browse files
authored
Benchmark tool: add option for build repo to benchmark against. (#3808)
* Benchmark tool: add option for build repo to benchmark against. * Address review comments.
1 parent afd2645 commit 32e3816

7 files changed

+54
-2
lines changed

_benchmark/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@ Benchmarks `build_runner` against synthetic codebases applying real generators:
44
Example usage:
55

66
```
7-
dart run _benchmark --generator=built_value benchmark
7+
# Benchmark `build_runner` from pub.
8+
dart run _benchmark \
9+
--generator=built_value \
10+
benchmark
11+
12+
# Benchmark a local version of `build_runner`.
13+
dart run _benchmark \
14+
--generator=built_value \
15+
--build-repo-path=$PWD/.. \
16+
benchmark
817
```

_benchmark/bin/_benchmark.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ final commandRunner =
1616
..addCommand(BenchmarkCommand())
1717
..addCommand(MeasureCommand())
1818
..addCommand(CreateCommand())
19+
..argParser.addOption(
20+
'build-repo-path',
21+
help: 'Path to build repo to benchmark.',
22+
)
1923
..argParser.addOption(
2024
'generator',
2125
help: 'Generator to benchmark.',

_benchmark/lib/benchmarks/built_value_generator_benchmark.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ dependencies:
3333
dev_dependencies:
3434
build_runner: any
3535
built_value_generator: any
36+
37+
${config.dependencyOverrides}
3638
''',
3739
);
3840

_benchmark/lib/benchmarks/freezed_generator_benchmark.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ dependencies:
3333
dev_dependencies:
3434
build_runner: any
3535
freezed: any
36+
37+
${config.dependencyOverrides}
3638
''',
3739
);
3840

_benchmark/lib/benchmarks/json_serializable_generator_benchmark.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ dependencies:
3434
dev_dependencies:
3535
build_runner: any
3636
json_serializable: any
37+
38+
${config.dependencyOverrides}
3739
''',
3840
);
3941

_benchmark/lib/benchmarks/mockito_generator_benchmark.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ dependencies:
3535
3636
dev_dependencies:
3737
build_runner: any
38+
39+
${config.dependencyOverrides}
3840
''',
3941
);
4042

_benchmark/lib/config.dart

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ import 'workspace.dart';
1111

1212
/// Benchmark tool config.
1313
class Config {
14+
final String? buildRepoPath;
1415
final Generator generator;
1516
final Directory rootDirectory;
1617
final List<int> sizes = const [1, 100, 250, 500, 750, 1000];
1718

18-
Config({required this.generator, required this.rootDirectory});
19+
Config({
20+
required this.buildRepoPath,
21+
required this.generator,
22+
required this.rootDirectory,
23+
});
1924

2025
factory Config.fromArgResults(ArgResults argResults) => Config(
26+
buildRepoPath: argResults['build-repo-path'] as String?,
2127
generator: Generator.values.singleWhere(
2228
(e) => e.packageName == argResults['generator'],
2329
),
@@ -41,4 +47,29 @@ class RunConfig {
4147
required this.size,
4248
required this.paddedSize,
4349
});
50+
51+
String get dependencyOverrides {
52+
final buildRepoPath = config.buildRepoPath;
53+
if (buildRepoPath == null) return '';
54+
55+
return '''
56+
dependency_overrides:
57+
build:
58+
path: $buildRepoPath/build
59+
build_config:
60+
path: $buildRepoPath/build_config
61+
build_modules:
62+
path: $buildRepoPath/build_modules
63+
build_resolvers:
64+
path: $buildRepoPath/build_resolvers
65+
build_runner:
66+
path: $buildRepoPath/build_runner
67+
build_runner_core:
68+
path: $buildRepoPath/build_runner_core
69+
build_test:
70+
path: $buildRepoPath/build_test
71+
build_web_compilers:
72+
path: $buildRepoPath/build_web_compilers
73+
''';
74+
}
4475
}

0 commit comments

Comments
 (0)