Skip to content

Commit f7cf069

Browse files
committed
Add benchmarks for when there is mostly no codegen.
1 parent d0ef60b commit f7cf069

File tree

7 files changed

+61
-21
lines changed

7 files changed

+61
-21
lines changed

_benchmark/bin/_benchmark.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ final commandRunner =
4848
allowed: Shape.values.map((e) => e.name).toList(),
4949
)
5050
..argParser.addFlag(
51-
'use-experimental-resolver',
52-
help: 'Whether to pass `--use-experimental-resolver` to build_runner.',
51+
'mostly-no-codegen',
52+
help: 'Whether to generate mostly source with no codegen.',
5353
);
5454

5555
Future<void> main(List<String> arguments) async {

_benchmark/lib/benchmarks/built_value_generator_benchmark.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies:
3232
3333
dev_dependencies:
3434
build_runner: any
35-
built_value_generator: any
35+
built_value_generator: ^8.11.0-dev
3636
3737
${config.dependencyOverrides}
3838
''',
@@ -56,9 +56,20 @@ ${config.dependencyOverrides}
5656
libraryNumber,
5757
benchmarkSize: size,
5858
);
59-
workspace.write(
60-
'lib/$libraryName',
61-
source: '''
59+
if (config.config.mostlyNoCodegen && libraryNumber > 1) {
60+
workspace.write(
61+
'lib/$libraryName',
62+
source: '''
63+
// ignore_for_file: unused_import
64+
${[for (final importName in importNames) "import '$importName';"].join('\n')}
65+
66+
class Value {}
67+
''',
68+
);
69+
} else {
70+
workspace.write(
71+
'lib/$libraryName',
72+
source: '''
6273
// ignore_for_file: unused_import
6374
import 'package:built_value/built_value.dart';
6475
@@ -71,7 +82,8 @@ abstract class Value implements Built<Value, ValueBuilder> {
7182
factory Value(void Function(ValueBuilder) updates) = _\$Value;
7283
}
7384
''',
74-
);
85+
);
86+
}
7587
}
7688
}
7789
}

_benchmark/lib/benchmarks/freezed_generator_benchmark.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,20 @@ ${config.dependencyOverrides}
6060
libraryNumber,
6161
benchmarkSize: size,
6262
);
63-
workspace.write(
64-
'lib/$libraryName',
65-
source: '''
63+
if (config.config.mostlyNoCodegen && libraryNumber > 1) {
64+
workspace.write(
65+
'lib/$libraryName',
66+
source: '''
67+
// ignore_for_file: unused_import
68+
${[for (final importName in importNames) "import '$importName';"].join('\n')}
69+
70+
class Value {}
71+
''',
72+
);
73+
} else {
74+
workspace.write(
75+
'lib/$libraryName',
76+
source: '''
6677
// ignore_for_file: unused_import
6778
import 'package:freezed_annotation/freezed_annotation.dart';
6879
@@ -75,7 +86,8 @@ class Value with _\$Value {
7586
const factory Value() = _Value;
7687
}
7788
''',
78-
);
89+
);
90+
}
7991
}
8092
}
8193
}

_benchmark/lib/benchmarks/json_serializable_generator_benchmark.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,20 @@ ${config.dependencyOverrides}
5757
libraryNumber,
5858
benchmarkSize: size,
5959
);
60-
workspace.write(
61-
'lib/$libraryName',
62-
source: '''
60+
if (config.config.mostlyNoCodegen && libraryNumber > 1) {
61+
workspace.write(
62+
'lib/$libraryName',
63+
source: '''
64+
// ignore_for_file: unused_import
65+
${[for (final importName in importNames) "import '$importName';"].join('\n')}
66+
67+
class Value {}
68+
''',
69+
);
70+
} else {
71+
workspace.write(
72+
'lib/$libraryName',
73+
source: '''
6374
// ignore_for_file: unused_import
6475
import 'package:json_annotation/json_annotation.dart';
6576
@@ -75,7 +86,8 @@ class Value {
7586
Map<String, dynamic> toJson() => _\$ValueToJson(this);
7687
}
7788
''',
78-
);
89+
);
90+
}
7991
}
8092
}
8193
}

_benchmark/lib/benchmarks/mockito_generator_benchmark.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class MockitoGeneratorBenchmark implements Benchmark {
1717

1818
@override
1919
void create(RunConfig config) {
20+
if (config.config.mostlyNoCodegen) {
21+
throw UnsupportedError(
22+
'Mockito benchmark does not support --mostly-no-codegen.',
23+
);
24+
}
2025
final workspace = config.workspace;
2126
final size = config.size;
2227

_benchmark/lib/config.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class Config {
1717
final List<Shape> shapes;
1818
final Directory rootDirectory;
1919
final List<int> sizes;
20-
final bool useExperimentalResolver;
2120
final bool allowFailures;
21+
bool mostlyNoCodegen;
2222

2323
Config({
2424
required this.allowFailures,
@@ -27,7 +27,7 @@ class Config {
2727
required this.rootDirectory,
2828
required this.sizes,
2929
required this.shapes,
30-
required this.useExperimentalResolver,
30+
required this.mostlyNoCodegen,
3131
});
3232

3333
factory Config.fromArgResults(ArgResults argResults) => Config(
@@ -45,7 +45,7 @@ class Config {
4545
argResults['shape'] == null
4646
? Shape.values
4747
: [Shape.values.singleWhere((e) => e.name == argResults['shape'])],
48-
useExperimentalResolver: argResults['use-experimental-resolver'] as bool,
48+
mostlyNoCodegen: argResults['mostly-no-codegen'] as bool,
4949
);
5050
}
5151

@@ -76,6 +76,8 @@ class RunConfig {
7676
dependency_overrides:
7777
build:
7878
path: $buildRepoPath/build
79+
built_value_generator:
80+
path: /usr/local/google/home/davidmorgan/git/built_value/built_value_generator
7981
build_config:
8082
path: $buildRepoPath/build_config
8183
build_modules:

_benchmark/lib/workspace.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class Workspace {
6060
'build_runner',
6161
'build',
6262
'-d',
63-
if (config.useExperimentalResolver) '--use-experimental-resolver',
6463
], workingDirectory: directory.path);
6564
var exitCode = await process.exitCode;
6665
if (exitCode == 0) {
@@ -81,7 +80,6 @@ class Workspace {
8180
'build_runner',
8281
'build',
8382
'-d',
84-
if (config.useExperimentalResolver) '--use-experimental-resolver',
8583
], workingDirectory: directory.path);
8684
exitCode = await process.exitCode;
8785
if (exitCode == 0) {
@@ -101,7 +99,6 @@ class Workspace {
10199
'build_runner',
102100
'build',
103101
'-d',
104-
if (config.useExperimentalResolver) '--use-experimental-resolver',
105102
], workingDirectory: directory.path);
106103
exitCode = await process.exitCode;
107104
if (exitCode == 0) {

0 commit comments

Comments
 (0)