Roll benchmark_harness and use AsyncBenchmarkBase.

Change-Id: I9089b566082d06cb4947e9720cbafedccc901a60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242872
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Jonas Termansen <sortie@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Jonas Termansen 2022-05-02 09:27:49 +00:00 committed by Commit Bot
parent 2316c7291c
commit 630302b710
7 changed files with 4 additions and 221 deletions

2
DEPS
View file

@ -79,7 +79,7 @@ vars = {
"args_rev": "3b3f55766af13d895d2020ec001a28e8dc147f91",
"async_rev": "f3ed5f690e2ec9dbe1bfc5184705575b4f6480e5",
"bazel_worker_rev": "ceeba0982d4ff40d32371c9d35f3d2dc1868de20",
"benchmark_harness_rev": "6a99d14719ef3f251041a9fcbe0589f312499696",
"benchmark_harness_rev": "0530da692a5d689f4b5450a7c8d1a8abe3e2d555",
"boolean_selector_rev": "437e7f06c7e416bed91e16ae1df453555897e945",
"boringssl_gen_rev": "ced85ef0a00bbca77ce5a91261a5f2ae61b1e62f",
"boringssl_rev": "87f316d7748268eb56f2dc147bd593254ae93198",

View file

@ -7,7 +7,7 @@
import 'dart:async';
import 'async_benchmark_base.dart' show AsyncBenchmarkBase;
import 'package:benchmark_harness/benchmark_harness.dart';
class MockClass {
static final String str = "${int.parse('42')}";

View file

@ -1,68 +0,0 @@
// 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 'package:benchmark_harness/benchmark_harness.dart'
show PrintEmitter, ScoreEmitter;
// Similar to BenchmarkBase from package:benchmark_harness.
class AsyncBenchmarkBase {
final String name;
final ScoreEmitter emitter;
// Empty constructor.
const AsyncBenchmarkBase(this.name, {this.emitter = const PrintEmitter()});
// The benchmark code.
// This function is not used, if both [warmup] and [exercise] are overwritten.
Future<void> run() async {}
// Runs a short version of the benchmark. By default invokes [run] once.
Future<void> warmup() async {
await run();
}
// Exercises the benchmark. By default invokes [run] 10 times.
Future<void> exercise() async {
for (var i = 0; i < 10; i++) {
await run();
}
}
// Not measured setup code executed prior to the benchmark runs.
Future<void> setup() async {}
// Not measures teardown code executed after the benchark runs.
Future<void> teardown() async {}
// Measures the score for this benchmark by executing it repeatedly until
// time minimum has been reached.
static Future<double> measureFor(Function f, int minimumMillis) async {
final int minimumMicros = minimumMillis * 1000;
int iter = 0;
final watch = Stopwatch();
watch.start();
int elapsed = 0;
while (elapsed < minimumMicros) {
await f();
elapsed = watch.elapsedMicroseconds;
iter++;
}
return elapsed / iter;
}
// Measures the score for the benchmark and returns it.
Future<double> measure() async {
await setup();
// Warmup for at least 100ms. Discard result.
await measureFor(warmup, 100);
// Run the benchmark for at least 2000ms.
final result = await measureFor(exercise, 2000);
await teardown();
return result;
}
Future<void> report() async {
emitter.emit(name, await measure());
}
}

View file

@ -9,7 +9,7 @@
import 'dart:async';
import 'async_benchmark_base.dart' show AsyncBenchmarkBase;
import 'package:benchmark_harness/benchmark_harness.dart';
class MockClass {
static final String str = "${int.parse('42')}";

View file

@ -1,68 +0,0 @@
// 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 'package:benchmark_harness/benchmark_harness.dart'
show PrintEmitter, ScoreEmitter;
// Similar to BenchmarkBase from package:benchmark_harness.
class AsyncBenchmarkBase {
final String name;
final ScoreEmitter emitter;
// Empty constructor.
const AsyncBenchmarkBase(this.name, {this.emitter = const PrintEmitter()});
// The benchmark code.
// This function is not used, if both [warmup] and [exercise] are overwritten.
Future<void> run() async {}
// Runs a short version of the benchmark. By default invokes [run] once.
Future<void> warmup() async {
await run();
}
// Exercises the benchmark. By default invokes [run] 10 times.
Future<void> exercise() async {
for (var i = 0; i < 10; i++) {
await run();
}
}
// Not measured setup code executed prior to the benchmark runs.
Future<void> setup() async {}
// Not measures teardown code executed after the benchark runs.
Future<void> teardown() async {}
// Measures the score for this benchmark by executing it repeatedly until
// time minimum has been reached.
static Future<double> measureFor(Function f, int minimumMillis) async {
final int minimumMicros = minimumMillis * 1000;
int iter = 0;
final watch = Stopwatch();
watch.start();
int elapsed = 0;
while (elapsed < minimumMicros) {
await f();
elapsed = watch.elapsedMicroseconds;
iter++;
}
return elapsed / iter;
}
// Measures the score for the benchmark and returns it.
Future<double> measure() async {
await setup();
// Warmup for at least 100ms. Discard result.
await measureFor(warmup, 100);
// Run the benchmark for at least 2000ms.
final result = await measureFor(exercise, 2000);
await teardown();
return result;
}
Future<void> report() async {
emitter.emit(name, await measure());
}
}

View file

@ -6,8 +6,7 @@ import 'dart:async';
import 'dart:isolate';
import 'dart:typed_data';
import 'package:benchmark_harness/benchmark_harness.dart'
show PrintEmitter, ScoreEmitter;
import 'package:benchmark_harness/benchmark_harness.dart';
class SendReceiveBytes extends AsyncBenchmarkBase {
SendReceiveBytes(String name,
@ -35,46 +34,6 @@ class SendReceiveBytes extends AsyncBenchmarkBase {
late SendReceiveHelper helper;
}
// Identical to BenchmarkBase from package:benchmark_harness but async.
abstract class AsyncBenchmarkBase {
final String name;
final ScoreEmitter emitter;
Future<void> run();
Future<void> setup();
Future<void> teardown();
const AsyncBenchmarkBase(this.name, {this.emitter = const PrintEmitter()});
// Returns the number of microseconds per call.
Future<double> measureFor(int minimumMillis) async {
final minimumMicros = minimumMillis * 1000;
int iter = 0;
final watch = Stopwatch();
watch.start();
int elapsed = 0;
while (elapsed < minimumMicros) {
await run();
elapsed = watch.elapsedMicroseconds;
iter++;
}
return elapsed / iter;
}
// Measures the score for the benchmark and returns it.
Future<double> measure() async {
await setup();
await measureFor(500); // warm-up
final result = await measureFor(4000); // actual measurement
await teardown();
return result;
}
Future<void> report() async {
emitter.emit(name, await measure());
}
}
class StartMessage {
final SendPort sendPort;
final bool useTransferable;

View file

@ -38,46 +38,6 @@ class SendReceiveBytes extends AsyncBenchmarkBase {
SendReceiveHelper helper;
}
// Identical to BenchmarkBase from package:benchmark_harness but async.
abstract class AsyncBenchmarkBase {
final String name;
final ScoreEmitter emitter;
Future<void> run();
Future<void> setup();
Future<void> teardown();
const AsyncBenchmarkBase(this.name, {this.emitter = const PrintEmitter()});
// Returns the number of microseconds per call.
Future<double> measureFor(int minimumMillis) async {
final minimumMicros = minimumMillis * 1000;
int iter = 0;
final watch = Stopwatch();
watch.start();
int elapsed = 0;
while (elapsed < minimumMicros) {
await run();
elapsed = watch.elapsedMicroseconds;
iter++;
}
return elapsed / iter;
}
// Measures the score for the benchmark and returns it.
Future<double> measure() async {
await setup();
await measureFor(500); // warm-up
final result = await measureFor(4000); // actual measurement
await teardown();
return result;
}
Future<void> report() async {
emitter.emit(name, await measure());
}
}
class StartMessage {
final SendPort sendPort;
final bool useTransferable;