mirror of
https://github.com/dart-lang/sdk
synced 2024-10-03 00:29:50 +00:00
[benchmarks/nnbd] Migrate TypedDataDuplicate benchmark to NNBD
Also: * Clean up lints in both unmigrated and migrated versions of benchmarks. * Cache lists in local variables in Uint8ListCopyViaLoopBenchmark and Float64ListCopyViaLoopBenchmark to make the same number of field accesses as in other benchmarks, in order to make comparison between different ways of copying typed data more fair. Change-Id: I1e7e726ebf1f3cf6c199fce515c2a56d94576ba6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150280 Reviewed-by: Régis Crelier <regis@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
403955cf34
commit
889d6a9565
|
@ -10,27 +10,30 @@ import 'package:benchmark_harness/benchmark_harness.dart';
|
|||
|
||||
abstract class Uint8ListCopyBenchmark extends BenchmarkBase {
|
||||
final int size;
|
||||
Uint8List input;
|
||||
Uint8List result;
|
||||
late Uint8List input;
|
||||
late Uint8List result;
|
||||
|
||||
Uint8ListCopyBenchmark(String method, this.size)
|
||||
: super('TypedDataDuplicate.Uint8List.$size.$method');
|
||||
|
||||
@override
|
||||
void setup() {
|
||||
input = Uint8List(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (var i = 0; i < size; ++i) {
|
||||
input[i] = (i + 3) & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void warmup() {
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
run();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void teardown() {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (var i = 0; i < size; ++i) {
|
||||
if (result[i] != ((i + 3) & 0xff)) {
|
||||
throw 'Unexpected result';
|
||||
}
|
||||
|
@ -41,6 +44,7 @@ abstract class Uint8ListCopyBenchmark extends BenchmarkBase {
|
|||
class Uint8ListCopyViaFromListBenchmark extends Uint8ListCopyBenchmark {
|
||||
Uint8ListCopyViaFromListBenchmark(int size) : super('fromList', size);
|
||||
|
||||
@override
|
||||
void run() {
|
||||
result = Uint8List.fromList(input);
|
||||
}
|
||||
|
@ -49,31 +53,36 @@ class Uint8ListCopyViaFromListBenchmark extends Uint8ListCopyBenchmark {
|
|||
class Uint8ListCopyViaLoopBenchmark extends Uint8ListCopyBenchmark {
|
||||
Uint8ListCopyViaLoopBenchmark(int size) : super('loop', size);
|
||||
|
||||
@override
|
||||
void run() {
|
||||
result = Uint8List(input.length);
|
||||
final input = this.input;
|
||||
final result = Uint8List(input.length);
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
result[i] = input[i];
|
||||
}
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Float64ListCopyBenchmark extends BenchmarkBase {
|
||||
final int size;
|
||||
Float64List input;
|
||||
Float64List result;
|
||||
late Float64List input;
|
||||
late Float64List result;
|
||||
|
||||
Float64ListCopyBenchmark(String method, this.size)
|
||||
: super('TypedDataDuplicate.Float64List.$size.$method');
|
||||
|
||||
@override
|
||||
void setup() {
|
||||
input = Float64List(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (var i = 0; i < size; ++i) {
|
||||
input[i] = (i - 7).toDouble();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void teardown() {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (var i = 0; i < size; ++i) {
|
||||
if (result[i] != (i - 7).toDouble()) {
|
||||
throw 'Unexpected result';
|
||||
}
|
||||
|
@ -84,6 +93,7 @@ abstract class Float64ListCopyBenchmark extends BenchmarkBase {
|
|||
class Float64ListCopyViaFromListBenchmark extends Float64ListCopyBenchmark {
|
||||
Float64ListCopyViaFromListBenchmark(int size) : super('fromList', size);
|
||||
|
||||
@override
|
||||
void run() {
|
||||
result = Float64List.fromList(input);
|
||||
}
|
||||
|
@ -92,15 +102,18 @@ class Float64ListCopyViaFromListBenchmark extends Float64ListCopyBenchmark {
|
|||
class Float64ListCopyViaLoopBenchmark extends Float64ListCopyBenchmark {
|
||||
Float64ListCopyViaLoopBenchmark(int size) : super('loop', size);
|
||||
|
||||
@override
|
||||
void run() {
|
||||
result = Float64List(input.length);
|
||||
final input = this.input;
|
||||
final result = Float64List(input.length);
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
result[i] = input[i];
|
||||
}
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
main() {
|
||||
void main() {
|
||||
final sizes = [8, 32, 256, 16384];
|
||||
final benchmarks = [
|
||||
for (int size in sizes) ...[
|
||||
|
|
|
@ -16,21 +16,24 @@ abstract class Uint8ListCopyBenchmark extends BenchmarkBase {
|
|||
Uint8ListCopyBenchmark(String method, this.size)
|
||||
: super('TypedDataDuplicate.Uint8List.$size.$method');
|
||||
|
||||
@override
|
||||
void setup() {
|
||||
input = Uint8List(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (var i = 0; i < size; ++i) {
|
||||
input[i] = (i + 3) & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void warmup() {
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
run();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void teardown() {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (var i = 0; i < size; ++i) {
|
||||
if (result[i] != ((i + 3) & 0xff)) {
|
||||
throw 'Unexpected result';
|
||||
}
|
||||
|
@ -41,6 +44,7 @@ abstract class Uint8ListCopyBenchmark extends BenchmarkBase {
|
|||
class Uint8ListCopyViaFromListBenchmark extends Uint8ListCopyBenchmark {
|
||||
Uint8ListCopyViaFromListBenchmark(int size) : super('fromList', size);
|
||||
|
||||
@override
|
||||
void run() {
|
||||
result = Uint8List.fromList(input);
|
||||
}
|
||||
|
@ -49,11 +53,14 @@ class Uint8ListCopyViaFromListBenchmark extends Uint8ListCopyBenchmark {
|
|||
class Uint8ListCopyViaLoopBenchmark extends Uint8ListCopyBenchmark {
|
||||
Uint8ListCopyViaLoopBenchmark(int size) : super('loop', size);
|
||||
|
||||
@override
|
||||
void run() {
|
||||
result = Uint8List(input.length);
|
||||
final input = this.input;
|
||||
final result = Uint8List(input.length);
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
result[i] = input[i];
|
||||
}
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,15 +72,17 @@ abstract class Float64ListCopyBenchmark extends BenchmarkBase {
|
|||
Float64ListCopyBenchmark(String method, this.size)
|
||||
: super('TypedDataDuplicate.Float64List.$size.$method');
|
||||
|
||||
@override
|
||||
void setup() {
|
||||
input = Float64List(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (var i = 0; i < size; ++i) {
|
||||
input[i] = (i - 7).toDouble();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void teardown() {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (var i = 0; i < size; ++i) {
|
||||
if (result[i] != (i - 7).toDouble()) {
|
||||
throw 'Unexpected result';
|
||||
}
|
||||
|
@ -84,6 +93,7 @@ abstract class Float64ListCopyBenchmark extends BenchmarkBase {
|
|||
class Float64ListCopyViaFromListBenchmark extends Float64ListCopyBenchmark {
|
||||
Float64ListCopyViaFromListBenchmark(int size) : super('fromList', size);
|
||||
|
||||
@override
|
||||
void run() {
|
||||
result = Float64List.fromList(input);
|
||||
}
|
||||
|
@ -92,15 +102,18 @@ class Float64ListCopyViaFromListBenchmark extends Float64ListCopyBenchmark {
|
|||
class Float64ListCopyViaLoopBenchmark extends Float64ListCopyBenchmark {
|
||||
Float64ListCopyViaLoopBenchmark(int size) : super('loop', size);
|
||||
|
||||
@override
|
||||
void run() {
|
||||
result = Float64List(input.length);
|
||||
final input = this.input;
|
||||
final result = Float64List(input.length);
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
result[i] = input[i];
|
||||
}
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
main() {
|
||||
void main() {
|
||||
final sizes = [8, 32, 256, 16384];
|
||||
final benchmarks = [
|
||||
for (int size in sizes) ...[
|
||||
|
|
Loading…
Reference in a new issue