-
Notifications
You must be signed in to change notification settings - Fork 26
Add AsyncBenchmarkBase class #44
Conversation
Hi Kevin, I'd like to take over ownership of this package as we're now using it to benchmark the Dart SDK. Can you add me as an uploader for the https://pub.dev/packages/benchmark_harness package? |
lib/src/benchmark_base.dart
Outdated
run() async {} | ||
|
||
// Runs a short version of the benchmark. By default invokes [run] once. | ||
void warmup() async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Future, and likewise above and the other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/src/benchmark_base.dart
Outdated
for (int i = 0; i < 10; i++) { | ||
await run(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay story time. The class in package:benchmark_harness
is bug compatible with Golem and I need to keep them that way until I've migrated the benchmarks. Golem has an existing AsyncBenchmarkBase, and I need to keep this version compatible with it.
BenchmarkBase (including the one here) has a bug where it does ten iterations per exercise, but it doesn't multiply the final result by 10, meaning that it reports the time to run 10 iterations instead of 1. The documentation for this package mentions that.
The existing AsyncBenchmarkBase doesn't have that problem. It does one run per exercise. I need this version to be compatible with that. That's still not great because doing 10 iterations per exercise means less overhead checking the system time, but at least the results aren't misleading.
My intention is to take over this package and ensure there's a pair of sync/async base benchmark classes that report the time per iteration, and perhaps does 10 iterations per exercise.
So where does that leave you? I do need a class named AsyncBenchmarkBase that does one run per exercise and reports the time per iteration. This is results compatible with how we want things to be in the future. You can use that base class in your Isolates benchmark. When I make changes to this package in the future, I can update your benchmark while being results compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/src/benchmark_base.dart
Outdated
@@ -62,3 +62,64 @@ class BenchmarkBase { | |||
emitter.emit(name, measure()); | |||
} | |||
} | |||
|
|||
class AsyncBenchmarkBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this in its own async_benchmark_base.dart file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/src/benchmark_base.dart
Outdated
// Measures the score for this benchmark by executing it repeately until | ||
// time minimum has been reached. | ||
static Future<double> measureFor(Function f, int minimumMillis) async { | ||
int minimumMicros = minimumMillis * 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use final for variables that are assigned once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/src/benchmark_base.dart
Outdated
await measureFor(warmup, 100); | ||
// Run the benchmark for at least 2000ms. | ||
double result = await measureFor(exercise, 2000); | ||
await teardown(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this in a finally block. That's another difference between BenchmarkBase and AsyncBenchmarkBase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Just wanted to submit a PR like this, but it's already here. Can this be merged? |
@sortie Any update on this? I think the only thing missing from the code review would be to replace the Future<void> exercise() async {
for (int i = 0; i < 10; i++) {
await run();
}
} I think the async version of the benchmarks can be very helpful for comparing things like database performance. It would be great if this could be merged at some point. |
Yes, the plan is to do this work soon. |
If the only thing blocking this is the discussion about whether the number of iterations from the Apart from that, is there anything else to be decided before we can move forward here? |
lib/src/async_benchmark_base.dart
Outdated
final String name; | ||
final ScoreEmitter emitter; | ||
|
||
// Empty constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch the comments to triple slash dartdoc for documentation
lib/src/async_benchmark_base.dart
Outdated
const AsyncBenchmarkBase(this.name, {this.emitter = const PrintEmitter()}); | ||
|
||
// The benchmark code. | ||
// This function is not used, if both [warmup] and [exercise] are overwritten. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank dartdoc line between the first paragraph and the second per style.
Hi Martin, First up, I need to stabilize this package as it hasn't rolled into the Dart SDK in a long time. There's a slight risk that any of the changes in the meanwhile may have broken something. That roll is being done in https://dart-review.googlesource.com/c/sdk/+/212747 The PR has already been updated to be compatible with the historic AsyncBenchmarkBase behavior (which happens to be the intended behavior). I see a couple minor nits. I'll take a careful look once the Jonas |
The async benchmark harness accommodates tests that require async setup/teardown/run implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I took over this PR and got it over the finish line :)
…sync Add AsyncBenchmarkBase class
This is to accommodate tests that require async setup/teardown/run.