e4c8b49dcc
Change-Id: I1362ada67a02b0ed352612fc29c727e94d8cd254 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394901 Commit-Queue: Daco Harkes <dacoharkes@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com>
67 lines
1.6 KiB
Dart
67 lines
1.6 KiB
Dart
// Copyright (c) 2022, 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.
|
|
|
|
import 'dart:io';
|
|
|
|
Future<void> main() async {
|
|
final contents = [
|
|
header,
|
|
for (final size in sizes) generateSize(size),
|
|
].join('\n');
|
|
|
|
final uri = Platform.script.resolve('dart/benchmark_generated.dart');
|
|
|
|
await File.fromUri(uri).writeAsString(contents);
|
|
}
|
|
|
|
const sizes = [1, 32, 1024, 1024 * 32];
|
|
|
|
const header =
|
|
'''// Copyright (c) 2022, 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.
|
|
|
|
import 'dart:ffi';
|
|
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
import 'FfiStructCopy.dart';
|
|
''';
|
|
|
|
String generateSize(int size) => '''
|
|
final class Struct${size}Bytes extends Struct {
|
|
@Array($size)
|
|
external Array<Uint8> a0;
|
|
}
|
|
|
|
final class Struct${size}BytesWrapper extends Struct {
|
|
external Struct${size}Bytes nested;
|
|
}
|
|
|
|
final class Copy${size}Bytes extends StructCopyBenchmark {
|
|
@override
|
|
Pointer<Struct${size}BytesWrapper> from = nullptr;
|
|
@override
|
|
Pointer<Struct${size}BytesWrapper> to = nullptr;
|
|
|
|
Copy${size}Bytes() : super('FfiStructCopy.Copy${size}Bytes');
|
|
|
|
@override
|
|
int get copySizeInBytes => sizeOf<Struct${size}BytesWrapper>();
|
|
|
|
@override
|
|
void setup(int batchSize) {
|
|
from = calloc(batchSize);
|
|
to = calloc(batchSize);
|
|
}
|
|
|
|
@override
|
|
void run(int batchSize) {
|
|
for (int i = 0; i < batchSize; i++) {
|
|
to[i].nested = from[i].nested;
|
|
}
|
|
}
|
|
}
|
|
''';
|