Skip to content

Commit d1f2a68

Browse files
committed
Feedback
1 parent 61cde33 commit d1f2a68

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkgs/crypto/benchmark/benchmark.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:io' show exit, stderr;
56
import 'dart:typed_data';
67

78
import 'package:convert/convert.dart';
89
import 'package:crypto/crypto.dart';
910

1011
void main(List<String> args) {
1112
Hash? function;
13+
int? customSize;
1214

1315
void setFunction(Hash newFunction, String message) {
14-
if (function != null) throw ArgumentError('Hash function already set.');
16+
if (function != null) {
17+
stderr.writeln('Hash function already set.');
18+
exit(1);
19+
}
1520
function = newFunction;
1621
print('Using hash function $message');
1722
}
@@ -33,14 +38,22 @@ void main(List<String> args) {
3338
setFunction(sha512224, 'sha512/224');
3439
} else if (arg == 'sha512256') {
3540
setFunction(sha512256, 'sha512/256');
41+
} else if (arg.startsWith('--custom=')) {
42+
customSize = int.parse(arg.substring('--custom='.length));
3643
} else {
37-
throw ArgumentError('Unknown argument: $arg');
44+
stderr.writeln('Unknown argument: $arg');
45+
exit(1);
3846
}
3947
}
4048
if (function == null) {
4149
setFunction(md5, 'md5');
4250
}
4351

52+
if (customSize != null) {
53+
doIterationsChunk(function!, mb: customSize, iterations: 1, doPrint: true);
54+
return;
55+
}
56+
4457
// Warmup.
4558
doIterationsChunk(function!, mb: 1, iterations: 100, doPrint: false);
4659

0 commit comments

Comments
 (0)