mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:59:47 +00:00
4af8469493
* Added a name-filter to every benchmark. * Addressed lints. * We don't run the legacy copies anymore, so deleted dart2 dirs. Change-Id: I65705749c5c90aad77d1fb93ea4a0d4e8b656cd4 Cq-Include-Trybots: luci.dart.try:benchmark-linux-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301522 Reviewed-by: Jonas Termansen <sortie@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
55 lines
1.2 KiB
Dart
55 lines
1.2 KiB
Dart
// Copyright (c) 2021, 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.
|
|
|
|
// Micro-benchmark for creating TypeData lists from Pointers.
|
|
//
|
|
// The FfiMemory benchmark tests accessing memory through TypedData.
|
|
|
|
import 'dart:ffi';
|
|
|
|
import 'package:benchmark_harness/benchmark_harness.dart';
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
//
|
|
// Benchmark fixture.
|
|
//
|
|
|
|
// Number of repeats: 1000
|
|
const N = 1000;
|
|
|
|
class FromPointerInt8 extends BenchmarkBase {
|
|
Pointer<Int8> pointer = nullptr;
|
|
FromPointerInt8() : super('FfiAsTypedList.FromPointerInt8');
|
|
|
|
@override
|
|
void setup() => pointer = calloc(1);
|
|
@override
|
|
void teardown() => calloc.free(pointer);
|
|
|
|
@override
|
|
void run() {
|
|
for (var i = 0; i < N; i++) {
|
|
pointer.asTypedList(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Main driver.
|
|
//
|
|
|
|
void main(List<String> args) {
|
|
final benchmarks = [
|
|
FromPointerInt8.new,
|
|
];
|
|
|
|
final filter = args.firstOrNull;
|
|
for (var constructor in benchmarks) {
|
|
final benchmark = constructor();
|
|
if (filter == null || benchmark.name.contains(filter)) {
|
|
benchmark.report();
|
|
}
|
|
}
|
|
}
|