[benchmarks] Remove dynamic invocations in BigIntParsePrint benchmark

The dynamic invocations `sink1.codeUnits` and `sink2.isEven` can be slow
on dart2wasm.

They are done once in a few iterations, but the noise can still be
eliminated with a `if (runtimeFalse)` guard around the code that makes
sure the benchmarked code won't be optimized away.

Change-Id: Id85013fa4be1912d1c710cd119e9f6f1e77bcff4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373040
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Ömer Sinan Ağacan 2024-06-26 08:07:11 +00:00 committed by Commit Queue
parent 1e84b64a0e
commit 01cf48f653

View file

@ -14,15 +14,10 @@ import 'native_version_dummy.dart'
// Benchmark BigInt and Int64 formatting and parsing.
// A global sink that is used in the [check] method ensures that the results are
// not optimized.
// Global sinks used to ensure that the results are not optimized.
dynamic sink1, sink2;
void check(bool sink2isEven) {
if (sink1.codeUnits.last.isEven != sink2isEven) {
throw StateError('Inconsistent $sink1 vs $sink2');
}
}
final bool runtimeFalse = int.parse('1') == 0;
// These benchmarks measure digit-throughput for parsing and formatting.
//
@ -78,7 +73,10 @@ class ParseBigIntBenchmark extends Benchmark {
sink1 = s;
sink2 = b;
}
check(sink2.isEven);
if (runtimeFalse) {
print(sink1);
print(sink2);
}
}
}
@ -92,7 +90,10 @@ class ParseInt64Benchmark extends Benchmark {
sink1 = s;
sink2 = b;
}
check(sink2.isEven);
if (runtimeFalse) {
print(sink1);
print(sink2);
}
}
}
@ -106,7 +107,10 @@ class ParseIntBenchmark extends Benchmark {
sink1 = s;
sink2 = b;
}
check(sink2.isEven);
if (runtimeFalse) {
print(sink1);
print(sink2);
}
}
}
@ -120,7 +124,10 @@ class ParseJsBigIntBenchmark extends Benchmark {
sink1 = s;
sink2 = b;
}
check(nativeBigInt.isEven(sink2));
if (runtimeFalse) {
print(sink1);
print(sink2);
}
}
}
@ -148,7 +155,10 @@ class FormatBigIntBenchmark extends Benchmark {
sink1 = s;
sink2 = b;
}
check(sink2.isEven);
if (runtimeFalse) {
print(sink1);
print(sink2);
}
}
}
@ -177,7 +187,10 @@ class FormatIntBenchmark extends Benchmark {
sink1 = s;
sink2 = b;
}
check(sink2.isEven);
if (runtimeFalse) {
print(sink1);
print(sink2);
}
}
}
@ -205,7 +218,10 @@ class FormatInt64Benchmark extends Benchmark {
sink1 = s;
sink2 = b;
}
check(sink2.isEven);
if (runtimeFalse) {
print(sink1);
print(sink2);
}
}
}
@ -234,7 +250,10 @@ class FormatJsBigIntBenchmark extends Benchmark {
sink1 = s;
sink2 = b;
}
check(nativeBigInt.isEven(sink2));
if (runtimeFalse) {
print(sink1);
print(sink2);
}
}
}