Skip to content

Commit c1c8163

Browse files
committed
Format.
1 parent f91a09b commit c1c8163

15 files changed

+206
-201
lines changed

benchmark/custom_emitter_benchmark.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ class CustomEmitter implements ScoreEmitter {
1010
}
1111

1212
void main(List<String> args) {
13-
benchmark(
14-
'construct | Custom emitter',
15-
() {
16-
var list = <int>[for (var i = 0; i < 1000; ++i) i];
17-
},
18-
scoreEmitter: CustomEmitter(),
19-
);
13+
benchmark('construct | Custom emitter', () {
14+
var list = <int>[for (var i = 0; i < 1000; ++i) i];
15+
}, scoreEmitter: CustomEmitter());
2016
}

lib/src/base/benchmark_process_result.dart

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class BenchmarkProcessResult {
3434
true => arguments
3535
.where((arg) => arg != '--define=isBenchmarkProcess=true')
3636
.join(' '),
37-
false => arguments.join(' ')
37+
false => arguments.join(' '),
3838
};
3939
return executable +
4040
(args.isEmpty
@@ -64,14 +64,16 @@ extension BenchmarkProcess on Process {
6464
Encoding? stdoutEncoding = const Utf8Codec(), // Enables histogram output
6565
Encoding? stderrEncoding = const Utf8Codec(), // on windows.
6666
}) {
67-
return Process.run(executable, [...arguments, benchmarkFile.path],
68-
workingDirectory: workingDirectory,
69-
environment: environment,
70-
includeParentEnvironment: includeParentEnvironment,
71-
runInShell: runInShell,
72-
stdoutEncoding: stdoutEncoding,
73-
stderrEncoding: stderrEncoding)
74-
.then<BenchmarkProcessResult>((processResult) {
67+
return Process.run(
68+
executable,
69+
[...arguments, benchmarkFile.path],
70+
workingDirectory: workingDirectory,
71+
environment: environment,
72+
includeParentEnvironment: includeParentEnvironment,
73+
runInShell: runInShell,
74+
stdoutEncoding: stdoutEncoding,
75+
stderrEncoding: stderrEncoding,
76+
).then<BenchmarkProcessResult>((processResult) {
7577
return BenchmarkProcessResult(
7678
executable: executable,
7779
arguments: arguments,
@@ -128,60 +130,66 @@ extension BenchmarkUtils on BenchmarkProcessResult {
128130
final out = StringBuffer();
129131

130132
out.writeln('------- Summary -------- '.style(ColorProfile.dim));
131-
out.writeln('Total run time: ${duration.ssms.style(
132-
ColorProfile.success,
133-
)}');
133+
out.writeln('Total run time: ${duration.ssms.style(ColorProfile.success)}');
134134

135135
for (final result in results) {
136136
numberOfFailedBenchmarks += result.numberOfFailedBenchmarks;
137137
numberOfFailedGroups += result.numberOfFailedGroups;
138138
numberOfCompletedBenchmarks += result.numberOfCompletedBenchmarks;
139139
}
140140

141-
out.writeln('Completed benchmarks: '
142-
'${numberOfCompletedBenchmarks.toString().style(
143-
ColorProfile.success,
144-
)}.');
141+
out.writeln(
142+
'Completed benchmarks: '
143+
'${numberOfCompletedBenchmarks.toString().style(ColorProfile.success)}.',
144+
);
145145

146146
if (numberOfFailedBenchmarks > 0) {
147-
out.writeln('Benchmarks with errors: '
148-
'${numberOfFailedBenchmarks.toString().style(ColorProfile.error)}.');
147+
out.writeln(
148+
'Benchmarks with errors: '
149+
'${numberOfFailedBenchmarks.toString().style(ColorProfile.error)}.',
150+
);
149151
exitCode = ExitCode.someBenchmarksFailed;
150152
}
151153

152154
if (numberOfFailedGroups > 0) {
153-
out.writeln('Groups with errors: '
154-
'${numberOfFailedGroups.toString().style(ColorProfile.error)}.\n'
155-
'Some benchmarks may have been skipped!');
155+
out.writeln(
156+
'Groups with errors: '
157+
'${numberOfFailedGroups.toString().style(ColorProfile.error)}.\n'
158+
'Some benchmarks may have been skipped!',
159+
);
156160
exitCode = ExitCode.someGroupsFailed;
157161
}
158162

159163
if ((numberOfFailedBenchmarks > 0 || numberOfFailedGroups > 0) &&
160164
!isVerbose) {
161-
out.writeln('Try using the option '
162-
'${'--verbose'.style(ColorProfile.emphasize + Ansi.yellow)} or '
163-
'${'-v'.style(ColorProfile.emphasize + Ansi.yellow)} '
164-
'for more details.');
165+
out.writeln(
166+
'Try using the option '
167+
'${'--verbose'.style(ColorProfile.emphasize + Ansi.yellow)} or '
168+
'${'-v'.style(ColorProfile.emphasize + Ansi.yellow)} '
169+
'for more details.',
170+
);
165171
}
166172

167173
switch (exitCode) {
168174
case ExitCode.someBenchmarksFailed:
169-
out.writeln('Exiting with code '
170-
'${ExitCode.someBenchmarksFailed.code}: '
171-
'${ExitCode.someBenchmarksFailed.description.style(
172-
ColorProfile.error,
173-
)}');
175+
out.writeln(
176+
'Exiting with code '
177+
'${ExitCode.someBenchmarksFailed.code}: '
178+
'${ExitCode.someBenchmarksFailed.description.style(ColorProfile.error)}',
179+
);
174180
break;
175181
case ExitCode.allBenchmarksExecuted:
176-
out.writeln('${'Completed successfully.'.style(ColorProfile.success)}\n'
177-
'Exiting with code: 0.');
182+
out.writeln(
183+
'${'Completed successfully.'.style(ColorProfile.success)}\n'
184+
'Exiting with code: 0.',
185+
);
178186
break;
179187
case ExitCode.someGroupsFailed:
180-
out.writeln('Exiting with code '
181-
'${ExitCode.someGroupsFailed.code}: '
182-
'${ExitCode.someGroupsFailed.description.style(
183-
ColorProfile.error,
184-
)}');
188+
out.writeln(
189+
'Exiting with code '
190+
'${ExitCode.someGroupsFailed.code}: '
191+
'${ExitCode.someGroupsFailed.description.style(ColorProfile.error)}',
192+
);
185193
break;
186194
default:
187195
}

lib/src/base/group.dart

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ class Group {
2020
final parentGroup = Zone.current[#group] as Group?;
2121
if (parentGroup != null) {
2222
throw UnsupportedError(
23-
'${'Nested groups detected! '.style(ColorProfile.error)}'
24-
'Group ${description.style(ColorProfile.emphasize)} defined '
25-
'within group ${parentGroup.description.style(
26-
ColorProfile.emphasize,
27-
)}');
23+
'${'Nested groups detected! '.style(ColorProfile.error)}'
24+
'Group ${description.style(ColorProfile.emphasize)} defined '
25+
'within group ${parentGroup.description.style(ColorProfile.emphasize)}',
26+
);
2827
}
2928
}
3029

@@ -64,39 +63,29 @@ class Group {
6463
void run() {
6564
_throwIfNested();
6665
final watch = Stopwatch()..start();
67-
runZonedGuarded(
68-
body,
69-
((error, stack) {
70-
reportError(
71-
error,
72-
stack,
73-
description: description,
74-
duration: watch.elapsed,
75-
errorMark: groupErrorMark,
76-
);
77-
}),
78-
zoneValues: {#group: this},
79-
);
66+
runZonedGuarded(body, ((error, stack) {
67+
reportError(
68+
error,
69+
stack,
70+
description: description,
71+
duration: watch.elapsed,
72+
errorMark: groupErrorMark,
73+
);
74+
}), zoneValues: {#group: this});
8075
}
8176
}
8277

8378
/// Defines a benchmark group.
8479
///
8580
/// Note: Groups may not be nested.
86-
FutureOr<void> group(
87-
String description,
88-
FutureOr<void> Function() body,
89-
) async {
81+
FutureOr<void> group(String description, FutureOr<void> Function() body) async {
9082
final isAsync = (body is Future<void> Function());
9183

9284
if (isAsync) {
9385
description = hourGlass + description;
9486
}
9587

96-
final instance = Group(
97-
description.style(ColorProfile.group),
98-
body,
99-
);
88+
final instance = Group(description.style(ColorProfile.group), body);
10089
if (isAsync) {
10190
return instance.runAsync();
10291
} else {

lib/src/base/score.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import '../util/stats.dart';
33
/// Object holding sample stats and the duration it took to generate the
44
/// score sample.
55
class Score<T extends num> {
6-
Score(
7-
{required this.duration,
8-
required List<T> sample,
9-
required this.innerIter})
10-
: stats = Stats(sample);
6+
Score({
7+
required this.duration,
8+
required List<T> sample,
9+
required this.innerIter,
10+
}) : stats = Stats(sample);
1111

1212
/// Measured micro-benchmark duration
1313
final Duration duration;
1414

15-
/// Indicates if the a sample point was averaged over [iter] runs.
15+
/// Indicates if the a sample entry was averaged over [iter] runs.
1616
final int innerIter;
1717

1818
/// Scores and score stats (in microseconds).
@@ -22,6 +22,6 @@ class Score<T extends num> {
2222
late final ({String unit, int factor}) timeScale = switch (stats.mean) {
2323
> 1000000 => (unit: 's', factor: 1000000),
2424
> 1000 => (unit: 'ms', factor: 1000),
25-
_ => (unit: 'us', factor: 1)
25+
_ => (unit: 'us', factor: 1),
2626
};
2727
}

lib/src/command/benchmark_runner.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import 'report_command.dart';
55

66
class BenchmarkRunner extends CommandRunner {
77
BenchmarkRunner._()
8-
: super(
9-
'benchmark_runner',
10-
'Runs benchmarks. Prints and exports score reports.',
11-
);
8+
: super(
9+
'benchmark_runner',
10+
'Runs benchmarks. Prints and exports score reports.',
11+
);
1212

1313
static BenchmarkRunner? _instance;
1414

lib/src/command/export_command.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class ExportCommand extends ReportCommand {
2121
// final category = 'benchmark';
2222

2323
@override
24-
String get description => 'Exports benchmark scores. A custom file extension '
24+
String get description =>
25+
'Exports benchmark scores. A custom file extension '
2526
'and directory may be specified.';
2627

2728
static const _extension = 'extension';
@@ -64,15 +65,17 @@ class ExportCommand extends ReportCommand {
6465
// Starting processes.
6566
final fResults = <Future<BenchmarkProcessResult>>[];
6667
for (final file in benchmarkFiles) {
67-
fResults.add(BenchmarkProcess.runBenchmark(
68-
executable: 'dart',
69-
arguments: [
70-
'--define=isBenchmarkProcess=true',
71-
if (isVerbose) '--define=isVerbose=true',
72-
if (isMonochrome) '--define=isMonochrome=true',
73-
],
74-
benchmarkFile: file,
75-
));
68+
fResults.add(
69+
BenchmarkProcess.runBenchmark(
70+
executable: 'dart',
71+
arguments: [
72+
'--define=isBenchmarkProcess=true',
73+
if (isVerbose) '--define=isVerbose=true',
74+
if (isMonochrome) '--define=isMonochrome=true',
75+
],
76+
benchmarkFile: file,
77+
),
78+
);
7679
}
7780

7881
// Start subscription to progress indicator.
@@ -94,9 +97,7 @@ class ExportCommand extends ReportCommand {
9497

9598
final outputPath = outputDirectory.join(outputFileName);
9699

97-
print(
98-
'Writing scores to: '.style(ColorProfile.dim) + outputPath + '\n',
99-
);
100+
print('Writing scores to: '.style(ColorProfile.dim) + outputPath + '\n');
100101

101102
await writeTo(path: outputPath, contents: result.stdout);
102103

lib/src/command/report_command.dart

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ class ReportCommand extends Command {
4747
argResults!.rest.isEmpty ? 'benchmark' : argResults!.rest.first;
4848

4949
// Resolving test files.
50-
final (benchmarkFiles: benchmarkFiles, entityType: entityType) =
51-
await resolveBenchmarkFiles(searchDirectory);
50+
final (
51+
benchmarkFiles: benchmarkFiles,
52+
entityType: entityType,
53+
) = await resolveBenchmarkFiles(searchDirectory);
5254
if (benchmarkFiles.isEmpty) {
5355
print('');
54-
print('Could not resolve any benchmark files using path: '
55-
'${searchDirectory.style(ColorProfile.highlight)}\n');
56+
print(
57+
'Could not resolve any benchmark files using path: '
58+
'${searchDirectory.style(ColorProfile.highlight)}\n',
59+
);
5660
exit(ExitCode.noBenchmarkFilesFound.index);
5761
} else {
5862
if (entityType == FileSystemEntityType.directory) {
@@ -87,15 +91,17 @@ class ReportCommand extends Command {
8791
// Starting processes.
8892
final fResults = <Future<BenchmarkProcessResult>>[];
8993
for (final file in benchmarkFiles) {
90-
fResults.add(BenchmarkProcess.runBenchmark(
91-
executable: 'dart',
92-
arguments: [
93-
'--define=isBenchmarkProcess=true',
94-
if (isVerbose) '--define=isVerbose=true',
95-
if (isMonochrome) '--define=isMonochrome=true',
96-
],
97-
benchmarkFile: file,
98-
));
94+
fResults.add(
95+
BenchmarkProcess.runBenchmark(
96+
executable: 'dart',
97+
arguments: [
98+
'--define=isBenchmarkProcess=true',
99+
if (isVerbose) '--define=isVerbose=true',
100+
if (isMonochrome) '--define=isMonochrome=true',
101+
],
102+
benchmarkFile: file,
103+
),
104+
);
99105
}
100106

101107
// Start subscription to progress indicator.

0 commit comments

Comments
 (0)