dart-sdk/benchmarks/MD5/dart2/md5.dart
William Hesse ea5840c2c5 [benchmarks] Update legacy benchmarks to use the List.filled constructor
The legacy Dart 2.9 benchmarks that used the default List(int size)
constructor are changed to use the equivalent List.filled(size, null)
constructor, because the default List constructor is removed.

Bug: b/280275041
Change-Id: I2813537ae22e19d473abde70d677368940585423
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304700
Reviewed-by: Jonas Termansen <sortie@google.com>
Commit-Queue: William Hesse <whesse@google.com>
2023-05-22 14:14:42 +00:00

42 lines
942 B
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart=2.9
import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
const size = 8 * 1024;
const expected = '6556112372898c69e1de0bf689d8db26';
class MD5Bench extends BenchmarkBase {
List<int> data;
MD5Bench() : super('MD5') {
data = List<int>.filled(size, null);
for (int i = 0; i < data.length; i++) {
data[i] = i % 256;
}
}
@override
void warmup() {
for (int i = 0; i < 4; i++) {
run();
}
}
@override
void run() {
final hash = md5.convert(data);
if (hex.encode(hash.bytes) != expected) {
throw 'Incorrect HASH computed.';
}
}
}
void main() {
MD5Bench().report();
}