Skip to content

Commit

Permalink
WIP, not for submit: benchmark analyzer-based generation / incrementa…
Browse files Browse the repository at this point in the history
…l generation by number of files.
  • Loading branch information
davidmorgan committed Dec 20, 2024
1 parent 998d544 commit e1d7079
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 5 deletions.
57 changes: 57 additions & 0 deletions _test/bin/benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'dart:io';

import '../test/common/utils.dart';

Future<void> main() async {
// only works in test
inTest = false;
ensureCleanGitClient();
print('Initial build.');
await runBuild();
print('Done.');

print('Files,Build time/ms');
for (final size in [
100,
500,
1000,
1500,
2000,
2500,
3000,
3500,
4000,
4500,
5000,
]) {
stdout.write('$size,');

for (var i = 0; i != size; ++i) {
await createFile('lib/built_value${i + 1}.dart', '''
import 'package:built_value/built_value.dart';
part 'built_value${i + 1}.g.dart';
abstract class Value implements Built<Value, ValueBuilder> {
Value._();
factory Value([void Function(ValueBuilder)? updates]) = _\$Value;
}
''');
}
await runBuild();
await createFile('lib/built_value1.dart', '''
import 'package:built_value/built_value.dart';
part 'built_value1.g.dart';
abstract class Value implements Built<Value, ValueBuilder> {
int get x;
Value._();
factory Value([void Function(ValueBuilder)? updates]) = _\$Value;
}
''');
final stopwatch = Stopwatch()..start();
await runBuild();
print(stopwatch.elapsedMilliseconds);
}
}
10 changes: 10 additions & 0 deletions _test/lib/built_value1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:built_value/built_value.dart';



part 'built_value1.g.dart';

abstract class Value implements Built<Value, ValueBuilder> {
Value._();
factory Value([void Function(ValueBuilder)? updates]) = _$Value;
}
65 changes: 65 additions & 0 deletions _test/lib/built_value1.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions _test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ environment:
sdk: ^3.6.0

dependencies:
built_value: ^8.9.0
web: ^1.0.0

dev_dependencies:
Expand All @@ -18,6 +19,7 @@ dev_dependencies:
build_runner_core: any
build_test: any
build_web_compilers: any
built_value_generator: ^8.9.0
dart_flutter_team_lints: ^3.1.0
io: ^1.0.0
path: ^1.8.0
Expand Down
16 changes: 11 additions & 5 deletions _test/test/common/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_process/test_process.dart';

bool inTest = true;

Directory _generatedDir = Directory(p.join(_toolDir.path, 'generated'));
Directory _toolDir = Directory(p.join('.dart_tool', 'build'));

Expand Down Expand Up @@ -55,8 +57,8 @@ Future<ProcessResult> _runBuild(String command, List<String> args,
}

final result = await Process.run(command, args);
printOnFailure('${result.stdout}');
printOnFailure('${result.stderr}');
if (inTest) printOnFailure('${result.stdout}');
if (inTest) printOnFailure('${result.stderr}');
return result;
}

Expand Down Expand Up @@ -123,10 +125,14 @@ bool _gitIsClean() {
/// state for this directory after running the test.
void ensureCleanGitClient() {
var gitWasClean = _gitIsClean();
expect(gitWasClean, isTrue,
if (inTest) {expect(gitWasClean, isTrue,
reason: 'Not running on a clean git client, aborting test.\n');
} else {
if (!gitWasClean) throw 'Not running on a clean git client, aborting.';
}


addTearDown(_resetGitClient);
if (inTest) addTearDown(_resetGitClient);
}

Future<void> _resetGitClient() async {
Expand Down Expand Up @@ -216,7 +222,7 @@ Future<void> expectTestsPass(

Future<void> createFile(String path, String contents) async {
var file = File(path);
expect(await file.exists(), isFalse);
if (inTest) expect(await file.exists(), isFalse);
await file.create(recursive: true);
await file.writeAsString(contents);
}
Expand Down

0 comments on commit e1d7079

Please sign in to comment.